Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

filter posts by meta value wordpress

add_action( 'pre_get_posts' , 'my_pre_get_posts' );

  function my_pre_get_posts( $query ) {

    // Check this is main query and other conditionals as needed
    if( $query->is_main_query() ) {
        $query->set( 
          'meta_query', 
          array( 
            array(
              'key' => 'project_cat',
              'value' => 'my-value'
            )
          )
        );
    }

  }
Source by wordpress.stackexchange.com #
 
PREVIOUS NEXT
Tagged: #filter #posts #meta #wordpress
ADD COMMENT
Topic
Name
3+9 =