0

I have 'category_preferences' saved in each user_meta which is an array of term IDs of a custom taxonomy. The custom taxonomy has ~100 items. As an example of the meta field value, where 14 and 15 are the term IDs:

array (size=1)
 0 => string 'a:2:{i:0;s:2:"14";i:1;s:2:"15";}' (length=32)

What would be the most efficient way of performing a custom post type query that returns a list of posts that match at least one of the 'saved' category preferences?

0

Use get_posts with a taxonomy query:

$prefs = array(array('14','15'));
$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => 'custom_tax_name',
            'terms' => $prefs[0],
            'operator' => 'IN'
        )
    )
);
$postslist = get_posts( $args );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.