SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Meta values and query_posts

    Hi All,

    So I'm stuck - I've trawled through the codex and tried different variations of google searches but I've had no luck.

    Basically I've got a custom meta box on pages that allows me to feature the content on the front page. It has a tick box and an order field. What I'm trying to do is update the query on the front page to take acount of the order field. At the moment I'm just pulling back posts that have the existing meta key "_my_meta" (code below).

    What I want to do is pull back posts that have the meta key "_my_meta", the meta value "featured" and order them by the meta value "order" (both featured and order are stored in an array in _my_meta). Can anyone help?

    PHP Code:
    $args = array(
        
    'post_type'      => array( 'post''page''news''llc_events' ),
        
    'meta_key'        => '_my_meta',
        
    'orderby'        => 'title',
        
    'order'            => 'ASC'
    );


    // The Query
    query_posts$args ); 
    Cheers,
    Richard.

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2007
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    does this help?

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi wellyfish,

    I think it probably would however I've just changed orderby from title to meta_value and it works. I also changed from query_posts to WP_Query.

    To be honest I'm a bit mistified as to how this is working. The order is one element in an array so I assumed that the meta_value in the code below would return both:

    featured: yes
    order:1

    Hence why I was trying to seperate them. However WP seems to be picking up the order value and using it.

    The working code:
    PHP Code:
    $args = array(
        
    'post_type'      => array( 'post''page''news''llc_events' ),
        
    'meta_key'        => '_my_meta',
        
    'orderby'        => 'meta_value',
        
    'order'            => 'ASC'
    );


    // The Query
    $the_query = new WP_Query$args ); 
    Thanks for the suggestion though.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •