error in wordpress query

1

Good morning everyone! I have the following query:

<?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 has some error, because whenever I delete, the listing of posts appears ... if I use meta_query to filter, it does not return anything, but I saw some pages that contain compatible content to be listed what can be made to make these parameters, correct ?? thank you all!! Good morning !!!

    
asked by anonymous 23.11.2018 / 11:27

1 answer

0

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

2-numberposts is used to query x number 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 you got confused, but I think it's worth clarifying here.

3- That way I did it will show 2 posts that the value of the field 'zone', is equal to one of the values: north ',' south ',' east ',' west ', follow the code: / p>

$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);

    
23.11.2018 / 21:49