Home Forums Front-end Issues Order By Not Working


Order By Not Working

  • I’m running this query:

    $posts = get_posts(array(
    ‘cat’ => 100,
    ‘posts_per_page’ => -1,
    ‘meta_key’ => ‘firstname’,
    ‘orderby’ => ‘meta_value’,
    ‘order’ => ‘ASC’

    But the orderby is not working. The field name mentioned in meta_key is correct. Could you please help me with this?

  • Actually, I think what is happening is that just one record is moving to the top of the list. For example, in the records for the custom post type, I have the following first names in order of most recent first:
    Regina, Anne, Lori, Laura.

    If I do not do the sort in the get_posts query, they are sorted as shown above; Regina is the first record, as that is the most recent one I added.

    If I do the sort in the get_posts query, Anne is moved to the top of the list and the remainder are in the order they were entered with most recent first:
    Anne, Regina, Lori, Laura

  • I found the solution. Apparently some time ago I had installed Post Types Order plug-in and it was active. I deactivated it a Wala — the order by works now! Ah, I just love it when I realize how stupid I am! LOL!

  • We are using relationship tables and are populating the selecting list by drop. While we are able to display the list properly sorted in the front-end based on the selected list in the admin page, we have a requirement to display all those products which are marked as discontinued at the bottom. Can you please help me with this.

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

The topic ‘Order By Not Working’ is closed to new replies.