I have a problem with a pre_get_pots function for the archive page tag (is_tag()). I want to add some posts to diplay on the archive page tag, with meta_query, corresponding to a meta field (of post).

Here is my function

function add_posts_on_tag_archive($query) {
    $tag = get_queried_object_id(); 
    $meta_query = array(
           'key'        => 'lj_bottom_tags',
           'value'      =>  $tag,
          'compare'     => 'LIKE',
   $query->set('meta_query', $meta_query); 
add_action('pre_get_posts', 'add_posts_on_tag_archive'); 

The problem is that the posts are only displayed in the following case: when the tags and the meta field are set.

Thank in advance.

Your Answer

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

Browse other questions tagged or ask your own question.