Answer the question
In order to leave comments, you need to log in
advanced custom fields. What value to choose for post_object?
Hello!
I have a project where I have product categories and products themselves. I need to display products in a certain category through a custom field.
I used acf and created a post_object on the product page. but with this that I came up with, I managed to display all the products where no category options were selected at all
$args = array(
'numberposts' => -1,
'post_type' => 'watch-page',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'category_to_select',
'compare' => '!='
),
)
);
// query
$the_query = new WP_Query( $args );
Answer the question
In order to leave comments, you need to log in
The task is solved in a strange way - ACF is generally useless here.
You have a custom post type (watch-page), create and link a custom taxonomy to it (for example, watch-page__tax), create the necessary categories.
If everything is done correctly, then in the admin panel when creating a post on the right, you can specify the desired category (or several).
Well, then
$query = new WP_Query([
'post_type' => 'watch-page',
'tax_query' => [
[
'taxonomy' => 'watch-page__tax',
'field' => 'name',
'terms' => 'Название категории'
]
]
]);
Maxim Morev thanks for the help, opened my eyes for me
It was just necessary to create a taxonomy with the_loop standard loop
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question