Answer the question
In order to leave comments, you need to log in
get_post() doesn't work with custom field, what's the problem?
The essence of the problem is as follows.
It is necessary to display posts sorted by an arbitrary field, but nothing works ... look at the code, maybe you will see something, thanks, I've been struggling with this for two days now ...
if ($rand == 1 ){
$args = array(
'post_type' => 'wsp_site',
'portfolio' => $port,
'numberposts' => $count,
'tax_query' => array(
array(
'taxonomy' => 'portfolio',
'field' => 'term_id',
'terms' => $id_port,),),
'orderby' => 'rand',
);
wsp_view ($sites = get_posts ($args), $col);
}
if ($rand == 2 ) {
$args = array(
'post_type' => 'wsp_site',
'portfolio' => $port,
'numberposts' => $count,
'tax_query' => array(
array(
'taxonomy' => 'portfolio',
'field' => 'term_id',
'terms' => $id_port,),),
'orderby' => 'wsp_weight', /*здесь проблема*/
'order' => 'ASC'
);
print_r($args);
wsp_view ($sites = get_posts ($args), $col);
}
Answer the question
In order to leave comments, you need to log in
Custom fields are meta data that is stored in a special way. Therefore, you need to order the selection by meta_value, and pass the field name in meta_query (or meta_key). This is how it should work.
$args = array(
'post_type' => 'wsp_site',
'portfolio' => $port,
'numberposts' => $count,
'tax_query' => array(
array(
'taxonomy' => 'portfolio',
'field' => 'term_id',
'terms' => $id_port,),),
'orderby' => 'meta_value',
'meta_key' => 'wsp_weight',
'order' => 'ASC'
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question