List all posts with 2 terms of a taxonomy - Wordpress Solution
I’m trying to list all the posts with a taxonomy called ”priority” in a particular order in a category page.
1.) All posts that has checked ”gold” should come first in alphabetic order.
2.) Posts that has checked ”silver” comes right after (in alphabetic order).
When there is more than, let's say 5 posts in the whole list, there should be a paging function.
Any ideas?
My live test site:
[[LINK href="http://www.u7322036.fsdata.se/advokat/category/new-york/"]]http://www.u7322036.fsdata.se/advokat/category/new-york/[[/LINK]]
The attached image shows how it should work.
I think, there is no way to do this with native WP_Query
[[LINK href="http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters"]]http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters[[/LINK]]
You should change priority as meta filed instead of taxonomy:
[[LINK href="http://www.wpquestions.com/question/showChronoLoggedIn/id/9599"]]http://www.wpquestions.com/question/showChronoLoggedIn/id/9599[[/LINK]]
Interesting approach, do you have a suggestion how the code should look like in this case?
The posts are regular posts.
try this code:
';
}
}
add_action('save_post', 'wpq_meta_priority_action');
function wpq_meta_priority_action($post_id) {
if(!isset($_POST['wpq_meta_priority_form_nonce'])) return $post_id;
if(!wp_verify_nonce($_POST['wpq_meta_priority_form_nonce'], 'wpq_meta_priority_form')) return $post_id;
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
update_post_meta($post_id, 'wpq_cf_priority', $_POST['wpq_cf_priority']);
}
add_action( 'pre_get_posts', 'wpq_pre_priority' );
function wpq_pre_priority( $query ) {
if ( !is_admin() AND $query->is_main_query() ) { //you can add your condition here
$query->set( 'meta_key', 'wpq_cf_priority' );
$query->set( 'orderby', 'meta_value' );
$query->set( 'order', 'DESC' );
}
return;
}
Solution - 1
I think, there is no way to do this with native WP_Query
[[LINK href="http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters"]]http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters[[/LINK]]
You should change priority as meta filed instead of taxonomy:
[[LINK href="http://www.wpquestions.com/question/showChronoLoggedIn/id/9599"]]http://www.wpquestions.com/question/showChronoLoggedIn/id/9599[[/LINK]]