skip to Main Content

When you create a post in WordPress, there’s a field called "order".

How can i make it work to for example, i put 5 and the post goes to the 5th position when displayed on the page?

I tried this but didn’t work:

<?php
            $args = array(
               'post_type' => 'team',
               'posts_per_page' => 30,
               'orderby' => 'meta_value_num',
               'order' => 'ASC'
            );
            $the_query = new WP_Query($args);
            if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post();
            ?>

2

Answers


  1. If "order" is a custom field, then you could do something like this:

    $the_query = new WP_Query(array(
        'post_type' => 'team',
        'posts_per_page' => 30,
        'meta_key' => 'order',
        'orderby' => 'meta_value',
        'order' => 'ASC',
      ));
    

    Let me know if it works for you!

    Login or Signup to reply.
  2. When the post is saved, WordPress takes the value from the "order" field and saves it to the wp_posts.menu_order column within the database. With that being said, you’ll want to set the "orderby" parameter to "menu_order".

    $args = array(
      'post_type' => 'team',
      'posts_per_page' => 30,
      'orderby' => 'menu_order',
      'order' => 'ASC'
    );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search