you all!
I have categories of Author
I have categories of Books
I have a custom post type Author. Author has custom fields:
I have a custom post type Book. Book has custom fields:
I need a query that return ALL BOOKs with Authors that have Contract ID = 1
And
I need a query that return ALL BOOKs with Type = Fiction
Thanks!!!
You should use meta_query to get the desired results:
I need a query that return ALL BOOKs with Authors that have Contract ID = 1
$freelance_books = get_posts(array(
'numberposts' => -1,
'post_type' => 'books',
'meta_key' => 'book_contract', // Adjust here with your field name
'meta_value' => 1
));
I need a query that return ALL BOOKs with Type = Fiction
$fiction_books = get_posts(array(
'numberposts' => -1,
'post_type' => 'books',
'meta_key' => 'book_type', // Adjust here with your field name
'meta_value' => 2
));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.