WordPress.org

Forums

Types - Custom Fields and Custom Post Types Management
[resolved] Help Ordering My Types Custom Field Query (5 posts)

  1. web-girl
    Member
    Posted 1 year ago #

    I have a query where I'm trying to retrieve posts in two categories, then order it by my custom field in ascending order. I've Googled a lot and can't seem to fix it. Can someone help me with this? I'm not sure what I'm missing. It seemed to work fine on my local installation of WordPress, but isn't working on the live site.

    wpcf-sortname is my custom field in the plugin.

    I'm using this code on a custom page template.

    <?php query_posts(array('category__and'=>array(48,38),'meta_key'=>wpcf-sortname,'orderby'=>meta_value,'order'=>ASC,'posts_per_page'=>-1));
    
    if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
        <a href="<?php the_permalink() ?>"><?php the_title(); ?></a><br />
        <?php endwhile; // end of the loop. ?>

    Thanks for the help!

    http://wordpress.org/extend/plugins/types/

  2. mbigul
    Member
    Plugin Author

    Posted 1 year ago #

    Dear web-girl,

    Query looks fine. Hope you are trying to list default "Post" entries. Please check case of your custom field is correct or not.

    [ Signature moderated. ]

  3. web-girl
    Member
    Posted 1 year ago #

    Thanks for helping! I checked the custom field and it looks okay. I am trying to list posts that are in the child category 48 and also in the child category 38 - do you think this is set up incorrectly? The query is retrieving all the posts correctly, just not sorting them in ascending order.

  4. web-girl
    Member
    Posted 1 year ago #

    Also, just to mention, I have wpcf-sortname as a textfield.

  5. mbigul
    Member
    Plugin Author

    Posted 1 year ago #

    Dear web-girl,

    Please check following tutorial for more details.

    http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

    [ Signature moderated. ]

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic