Written by Remi Corson.
you can for example query only posts from a specific type and with a custom meta field key equal to a determined value. In the code below, we are targeting only custom post type called “portfolio” where meta key “project_type” is set to “design”, that’s a typical query that can be used on a portfolio page.
// Load our function when hook is set add_action( 'pre_get_posts', 'rc_modify_query_get_design_projects' ); function rc_modify_query_get_design_projects( $query ) { // Check if on frontend and main query is modified if( ! is_admin() && $query->is_main_query() && $query->query_vars['post_type'] != 'portfolio' ) { $query->set('meta_key', 'project_type'); $query->set('meta_value', 'design'); } }
Revisions
- August 4, 2015 @ 05:18:53 [Current Revision] by PeterLugg
- August 4, 2015 @ 05:18:53 by PeterLugg
No comments yet.