0

I am trying to query child posts from two parents (that part is working fine),

... but now I want to exclude posts that have a meta_key of 'feature' with a meta_value of '1'

Using the Codex reference I've tried a couple of ways to write this, not working.

Here's what I've written thus far, I believe I'm close, but need help. Thank you!

<?php
    $argsthis = array(
    'post_status' => 'publish',
    'post_type' => 'page',
    'order' => 'DESC',
    'posts_per_page' => '5',
    'post_parent__in' => array(10,11),
    'meta_query' => array(
      array(
            'key'     => 'feature',
            'value'   => '1',
            'compare' => '!=',
            ),
        )
    );
?>

and I've tried, simply (w exact same result as above):

<?php
    $argsthis = array(
    'post_status' => 'publish',
    'post_type' => 'page',
    'order' => 'DESC',
    'posts_per_page' => '5',
    'post_parent__in' => array(10,11),
    'meta_key'     => 'feature',
    'meta_value'   => '1',
    'meta_compare' => '!=',
            ),
        )
    );
?>
6
  • In what way is it not working? Are you seeing posts with that meta_value in your results? Are you seeing no results?
    – mrwweb
    Sep 4, 2014 at 0:54
  • instead of showing my intention of all child pages of post_parent__in 10 and 11 except the page with custom field of meta_key=feature and meta_value=1; the page only displays one page from post_parent=10.
    – ccbar
    Sep 4, 2014 at 16:50
  • I would start by double- (or triple-!) checking that you have posts meeting those criteria. Then look in your database and see how the meta_value is being saved. Is it a string? An integer? Boolean even?
    – mrwweb
    Sep 4, 2014 at 16:52
  • Tripled checked, posts meet criteria. feature 1 and feature 2 query works as ir should for another query set up on the same page -- and my query for this issue works as it should except when I try to filter out feature 1.
    – ccbar
    Sep 4, 2014 at 17:47
  • OK, not sure what I'm looking at when checking the db -- but under postmeta table: meta_id is bigint, post_id is bigint, meta_key is varchar, meta_value is longtext. So I'm using characters for key and a number for value (which is OK for longtext?) and as I mentioned when querying for feature 1 and 2 (for another wp_query on same pg but not the query in this question) I use the same values for meta_key and meta_value an that query works fine.
    – ccbar
    Sep 4, 2014 at 17:53

1 Answer 1

0

This is what works in my query:

<?php
    $argsfeature = array(
    'post_status' => 'publish',
    'post_type' => 'page',
    'order' => 'DESC',
    'posts_per_page' => '1',
    'meta_key' => 'featuring',
    'meta_value' => '1' 
    );

    ?>

and this query works:

<?php
  $argsarticles = array(
   'post_status' => 'publish',
   'post_type' => 'page',
   'order' => 'DESC',
   'posts_per_page' => '5',
   'post_parent__in' => array(10,11)
    );
 ?>

what isn't working is "rewriting" the 2nd query listed above where I can get the child pages of 10 and 11, BUT NOT the pages that have already been pulled from the "featuring 1" query - the first query listed above.

Thank you so much for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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