A
A
Anton Seredny2017-10-05 20:42:00
WordPress
Anton Seredny, 2017-10-05 20:42:00

Select posts by additional taxonomy field?

There are posts on the site that have a custom taxonomy Tax (for example)
The taxonomy Tax itself has additional fields:

  • Field A
  • Field B
  • Field B
Task:
Select all posts with taxonomy terms Tax selected , while these terms have an additional field A = 100 .
At the same time, it is possible that a variant is possible when it will be necessary to select according to the above request + "posts with the Sample category set.
What to do in this case? Pull out absolutely all posts of this taxonomy and filter out in the loop by checking" is the additional field A = 100?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zorca, 2017-10-05
@zorca

You can simply compose the query as needed: https://carbonfields.net/docs/advanced-topics-quer...
All posts containing the crb_text field with the value 'hello world':

// field definition
Container::make( 'post_meta', __( 'Post Options', 'crb' ) )
    ->where( 'post_type', '=', 'post' )
    ->add_fields( array(
        Field::make( 'text', 'crb_text', 'Text' ),
    ) );

// query
$query = new WP_Query( array(
    'post_type'=>'post',
    'meta_query'=>array(
        array(
            'key' => 'crb_text',
            'value' => 'hello_world',
        ),
    ),
) );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question