Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress query_posts Order By Custom Field

i'm trying to order my results with query_posts function by a custom field.

Here is my edited query_posts() function:

query_posts( "post_type=produkte&".$query_string."&orderby=Price&order=DESC" );

The Price looks like that {Euro}.{Cent} for example 1.49.

And the query_posts() function orders it not right. The result is ordered like that:

0.49, 1.99, 0.99

What is going wrong?

Thanks in Advance!

like image 259
Jings Avatar asked Jun 10 '12 17:06

Jings


People also ask

How do I display ACF custom fields in frontend WordPress?

If you want to show the fields inside the post, you have to place the code inside the loop of "single. php", supposing you are using the standard post type. This code retrive the field only, it won't show anything, it's used to store the value in a variable: get_field('field-name');

How do I use custom fields in WordPress?

Simply create a new post or edit an existing one. Go to the custom fields meta box and select your custom field from the drop-down menu and enter its value. Click on the 'Add Custom Field' button to save your changes and then publish or update your post.


1 Answers

You may try this (hopefully it'll work/found online)

query_posts( "post_type=produkte&".$query_string."&meta_key=Price&orderby=meta_value_num&order=DESC" );

Another answer on SO.

like image 143
The Alpha Avatar answered Sep 30 '22 19:09

The Alpha