我有两种自定义帖子类型:Books 和Subjects. 对于此项目,我使用Super CPT创建自定义帖子类型:
$books = new Super_Custom_Post_Type( \'book\', \'\', \'book\', $register = array(
\'supports\' => array( \'title\', \'editor\', \'thumbnail\'),
)
);
$subjects= new Super_Custom_Post_Type( \'subject\', \'\', \'\', $register = array(
\'supports\' => array( \'title\', \'editor\'),
\'hierarchical\' => true,
)
);
为了选择本书的主题,我创建了一个元框和来自主题的值:
$profissionais->add_meta_box( array(
\'id\' => \'subjects\',
\'context\' => \'side\',
\'fields\' => array(
\'subjects\' => array( \'type\' => \'select\', \'label\' => \'\', \'data\' => \'subject\', \'multiple\' => \'multiple\' )
)
) );
现在,我需要在每个主题的页面上显示与此主题相关的书籍。我从以下内容开始:
$args = array(
\'post_type\' => \'book\',
);
$books = new WP_Query($args);
但我不知道如何前进。我正在尝试这样做:
SELECT book_title FROM books WHERE subject = subject page title
UPDATE
已解决!
$current = get_the_ID();
$args = array(
\'post_type\' => \'book\',
\'posts_per_page\' => -1,
\'meta_key\' => \'subjects\',
\'meta_value\' => $current,
);
$books = new WP_Query($args);