error in wordpress query

Asked

Viewed 25 times

1

I have the following appointment :

<?php
$footerlocal = array(    
    'numberposts' => 2, 
    'post_type' => 'page',       
    'meta_query' => array( 
    'relation' => 'OR',
        array(  'key' => 'zona', 'value' => '"norte"',  'compare' => 'LIKE'),
        array( 'key' => 'zona', 'value' => '"sul"', 'compare' => 'LIKE' ),
        array( 'key' => 'zona',  'value' => '"leste"', 'compare' => 'LIKE'  ),
        array( 'key' => 'zona', 'value' => '"oeste"',  'compare' => 'LIKE' ),
      )
 );
?>

well, in meta_query there is some error, because whenever I delete, the post listing appears...if I use meta_query to filter, it does not return anything, but I saw some pages containing content compatible to be listed what can be done to make these parameters correct?? thank you all!! good morning!!!

  • Welcome to Stackoverflow in English. I edited your question to remove the greetings as we usually keep the text as clean as possible to focus on your scheduling question. If you are interested in visiting a part of the site that is not aimed to ask questions can know the [chat]. If you have questions about the operation, rules and procedures of the site visit the [meta] :)

1 answer

0

1- To list wordpress posts, you need to put the value of 'post_type' as 'post', this way that you did: 'post_type' => 'page', is trying to query the pages created.

2- numberposts is used to query x amount of posts, while posts_per_page is used to list a number x of post per page, I do not know if it was purposeful or vc got confused, but I believe it is worth clarifying here.

3- This way I did will show 2 posts that the value of the field 'zone', is equal to one of the values: north', 'south', 'east', 'west', follows the code:

$args = array(
'post_type' => 'post',
'posts_per_page' => 2,
'tax_query' => array(
    array(
        'key'     => 'zona',
        'value'   => array( 'norte', 'sul', 'leste', 'oeste')
        'compare' => 'IN',
    )
),

); $query = new Wp_query( $args );

Browser other questions tagged

You are not signed in. Login or sign up in order to post.