• Hello,

    I searched but couldn’t find a solution to my problem.

    I’m using Magic Fields plugin for custom fields.

    For some post types i added order fields like ‘homepage_list_order’. But this field is not required.

    What i’m trying to do is if a value has been entered to ‘homepage_list_order’ use it if not put the post at the end of the list.

    Let’s say i have 10 posts.

    I want to show all of them on my homepage but with my custom order field ‘homepage_list_order’.

    I want to enter ‘homepage_list_order’ value for only 3 of them.

    When i open my homepage the 7 of them is at the top of the list and the 3 of them at the end.

    I guess, when i orderby meta_value_num, WP gets post but if field is empty, WP puts it on the top of list as considering the value is 0. However i want posts that have no meta_value at the end of the list. If i entered value for Post_5, Post_2, Post_9, i want just these 3 at top.

    Sometimes i have 100 posts and just want 3 of them to be at top. Even if i entered a value for these three like 1,2,3 they always are at bottom.

    I hope i could make you understand.

    Any help would be nice.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You might try making the posts with the order field values sticky. I’m not sure how that gets implemented, so couldn’t say for sure if this will work.

    You could always add the orderby direction option DESC (descending) to the query argument, then your posts will be listed 3,2,1,empty. You could then swap the 1 and 3 values so the post you want at top has the 3 value and the 3rd from top has the 1 value.

    Thread Starter meln

    (@meln)

    Thank you for reply.

    I can do that but it is hard to explain to customer ?? If there will no solution probably your suggestion will be best option.

    what if you separated it into two different queries? a query for the posts with the meta key first then a query for the normal posts afterwards?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Order By Meta Value Problem’ is closed to new replies.