Support

Account

Home Forums General Issues Ordering by field order

Solving

Ordering by field order

  • Is it possible, to order by field order?
    In the admin I can order the fields, but I have no idea how could I display the data in the same order.

    
    $args = array('post_type' => 'product',
    	     'posts_per_page' => 1,
    	     'orderby'		=> 'meta_value_num',
    	     'order'			=> 'ASC');
    $the_query = new WP_Query ($args);
    
    • Elliot

    • November 3, 2013 at 6:38 pm

    Hi @vakondweb

    Yes, you are on the right track.

    Your args are missing the meta_key for the order param to work correctly.

    Perhaps you just need to have another look at the docs:
    http://www.advancedcustomfields.com/resources/how-to/orde-posts-by-custom-fields/
    http://codex.wordpress.org/Class_Reference/WP_Query

  • Thanks but I have no idea what to put to the meta key.
    I cant find any reference regarding it. 🙁

    $args = array(‘post_type’ => ‘product’,
    ‘posts_per_page’ => 1,
    ‘meta_key’ = ‘?????’
    ‘orderby’ => ‘meta_value_num’,
    ‘order’ => ‘ASC’);
    $the_query = new WP_Query ($args);

    • Elliot

    • November 4, 2013 at 4:38 pm

    Hi @vakondweb

    the meta_key will be the name of the field you want to order by.

    How else would PW know what custom field value to use as the ordering?

  • But I want to use the order info from the admin.
    I would like display in the same order as I ordering the custom fields in admin area. I cant find meta key for doing this…

    • Elliot

    • November 5, 2013 at 9:39 am

    Hi @vakondweb

    Sorry, I dont understand what you are saying.

    Perhaps you should return to the original question and ask how to achieve the output you desire instead of asking about the meta_order argument.

    The WP_Query object is for querying posts in WordPress, this is different to loading ACF values. Does this help? Perhaps you are a bit confused and did not mean to use the WP_Query?

    Could this be correct?

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.