WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] help with page sorting by 2 meta boxes query args (6 posts)

  1. paperkawaii
    Member
    Posted 2 years ago #

    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:

    http://madeagency.com/vendome_new/products/

    http://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?

    :P

  2. egado
    Member
    Posted 2 years ago #

    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...

  3. paperkawaii
    Member
    Posted 2 years ago #

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

    x

  4. paperkawaii
    Member
    Posted 2 years ago #

    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.

    :)

  5. paperkawaii
    Member
    Posted 2 years ago #

    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

  6. egado
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic