• Resolved Chrissy

    (@paperkawaii)


    Hi I really hope someone can help, I have a page which I only want to call pages with the type ‘page’ and they have to have both meta boxes filled.

    I have this:

    <?php
    query_posts( array(
      'post_type' => 'page',
      'meta_key' => 'Featured',
      'meta_value' => 'yes',
      'meta_key' => 'type',
      'meta_value' => 'boucheron'
    ) );
    ?>

    But it shows the post even though it is not “Featured”…

    Do I need to put some kind of “and” thing in there?

    I am not a newby, but I’m new at php, just starting to do more advanced stuff.

    If you like you can take a look at what I’m building:

    https://madeagency.com/vendome_new/products/

    https://madeagency.com/vendome_new/products/boucheron-jewellery/

    If you look here, you can see the page template where I have the above code, and it’s pulling in a page that only has “boucheron” in the “type” meta box.

    Is there a better way of doing this?

    ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • Try this:

    <?php
    $args = array(
        'post_type' => 'page',
        'meta_query' => array(
    
            array(
                'key' => 'featured',
                'value' => 'true',
                'compare' => 'yes'
                ),
    
            array(
                'key' => 'type',
                'value' => 'true',
                'compare' => 'boucheron'
                )
    
        )
    );
    query_posts($args);
    ?>

    Only pages, which have set featured to yes and type to boucheron, will be shown… hope that is what you want ??

    Let me know if it works for you…

    Thread Starter Chrissy

    (@paperkawaii)

    Thanks, egado! I will try this today and let you know how it goes..

    x

    Thread Starter Chrissy

    (@paperkawaii)

    It didn’t work, when I added the code nothing appeared at all, I had a play and ended up with this:

    <?php
    $args = array(
        'post_type' => 'page',
        'meta_query' => array(
    
            array(
                'meta_key' => 'Featured',
                'meta_value' => 'Yes',
                'meta_key' => 'type',
                'meta_value' => 'boucheron',
                'compare' => 'Yes','boucheron'
                )
    
        )
    );
    query_posts($args);
    ?>

    But it is showing all the pages form ‘boucheron’ whether or not ‘featured’ is ‘yes’.

    I’m not too sure how that 'compare' => thing works, is there a website that can teach about that? I did search but couldn’t see it.

    ??

    Thread Starter Chrissy

    (@paperkawaii)

    Hi, I fixed it…

    <?php
    $args = array(
        'post_type' => 'page',
        'meta_query' => array(
    
            array(
                'meta_key' => 'Featured',
                'meta_value' => 'Yes',
                'compare' => '='
                ),
    	array(
                'key' => 'type',
                'value' => 'boucheron',
                'compare' => '='
                )
    
        )
    );
    query_posts($args);
    ?>

    Thanks for your help! XXX

    Thank you for the Feedback, so 'compare' => '=' was the solution ?? Tank you too.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘help with page sorting by 2 meta boxes query args’ is closed to new replies.