Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'pre_get_posts', 'wpse230535_custom_posts_by_custom_field' );
- function wpse230535_custom_posts_by_custom_field( $query ) {
- if( !is_admin() && is_archive( 'your-custom-post-type' ) && $query->is_main_query() ) {
- $query->set( 'meta_query', array (
- array (
- 'key' => 'custom-field-name',
- 'value' => 'custom-field-value',
- 'compare' => '=',
- ),
- ));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement