Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在wordpress中从自定义数据库表中检索自定义帖子?_Wordpress - Fatal编程技术网

如何在wordpress中从自定义数据库表中检索自定义帖子?

如何在wordpress中从自定义数据库表中检索自定义帖子?,wordpress,Wordpress,我正在开发一个wordpress插件。我已经创建了一个自定义的帖子,叫做departments。此外,我还将所有部门帖子存储在名为awr_departments table的自定义表中。现在,我想从自定义表awr\U departments中检索仪表板中的所有部门帖子,而不是从内置表wp\U帖子中检索。我知道数据库查询,但不知道在仪表板中为自定义帖子列表触发的钩子或过滤器。请指导我完成这项任务 注意:我不能更改核心wordpress文件,因为我想要插件本身的所有功能 这是我在自定义表中插入自定义

我正在开发一个wordpress插件。我已经创建了一个自定义的帖子,叫做departments。此外,我还将所有部门帖子存储在名为awr_departments table的自定义表中。现在,我想从自定义表awr\U departments中检索仪表板中的所有部门帖子,而不是从内置表wp\U帖子中检索。我知道数据库查询,但不知道在仪表板中为自定义帖子列表触发的钩子或过滤器。请指导我完成这项任务

注意:我不能更改核心wordpress文件,因为我想要插件本身的所有功能

这是我在自定义表中插入自定义帖子的代码

function save_awr_details(){
global $post;
  global $wpdb;

   if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
      return;

 if ( get_post_type($post) == 'awr_department'){  

  // $post->post_status='publish';
   if(isset($post->post_title)) {
      $check=$wpdb->insert( 
                    'awr_departments', 
                    array( 
                      'title' => $_POST['post_title'],
                    )
                  );
   }
 }
}
add_action('publish_awr_department', 'save_awr_details');

如果你想在wordpress仪表板上显示所有结果,你必须创建一个小部件,然后使用这个钩子

add_action('wp_dashboard_setup', 'yourcustom_dashboard_widget');

您可以使用它从数据库中检索数据

 $query = new WP_Query( array(
    'post_type' => 'awr_department', //your post name
    'posts_per_page' => -1,
    'order' => 'ASC',
    'orderby' => 'title',
) );