Answer the question
In order to leave comments, you need to log in
How to sort the output of posts by a custom field in Wordpress?
There is a site nashe-mesto.com/projects/?type=hitech-modern
I want to display records on this page in descending order of area. To do this, for this type of records, an arbitrary order_field field was created and sorting seems to be specified in the template. But it doesn't want to sort :(
Here is a piece of code from the template file of this page:
<?php get_header(); ?>
<?php
global $wp_query;
$ppr = 6;
$paged = ($wp_query->query_vars['paged']
) ?
_
_
_
_ -$ppr,
'orderby' => 'meta_value_num',
'meta_key' => 'order_field'
)
Unfortunately, I'm not good at this myself...
Answer the question
In order to leave comments, you need to log in
Perhaps the problem is exactly what values are stored in an arbitrary field. Try to enter whole numbers in several posts, for example: 10, 20, 30 and see if it works. In a piece of code, everything seems to be as it should be.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question