Sort by custom field that is an array?
Question
is it possible to sort posts inside a query based on post value that is in an array – but using the last element of the array?
The code looks something like:
<?php
$mostsharedposts= new WP_Query(
array( 'posts_per_page' => 10,
'meta_key' => 'mashsb_shares',
'orderby' => 'meta_value',
'order' => 'DESC' ) );
while ( $mostsharedposts->have_posts() ) : $mostsharedposts->the_post();
/* Loop here e.g.:*/
endwhile;
?>
meta_value
is an array, and I just need the last element of that array. Can I somehow extract that element in a variable, using explode()
and end()
and sort by that variable or …?
Any idea would be helpful 🙂
0
post-meta, wp-query
4 years
2020-02-08T08:38:31-05:00
2020-02-08T08:38:31-05:00 0 Answers
77 views
0
Leave an answer