Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

roxperez on "Order a WP_Query by a custom field that don´t exist in the query"

$
0
0

I have some problems trying to order a WP_Query, maybe someone can help me.

I´ve created a wp_query, the post_type is a custom post type from a plugin, so I cannot modify it.

I need to add an extra field to each post so I´ve done this (don´t know if this is correct):

while ( $query->have_posts() ) : $query->the_post();
$query->post->total = get_total(); endwhile;

Here I add an extra field "total" to the posts array.

The problem is that now I need to order the posts by this field (total) and I don´t know how to do it.

I´ve tried with get_posts, pre_get_posts but nothing works.

Can anyone help me? Thanks in advance


Viewing all articles
Browse latest Browse all 8245

Trending Articles