Support

Account

Home Forums General Issues Getting Field Value of A Different CPT through Relationship with WP_Query Reply To: Getting Field Value of A Different CPT through Relationship with WP_Query

  • function solution_directory( $query ) {
    	
    	if ( $query->is_main_query() && !$query->is_feed() && !is_admin() && $query->is_post_type_archive( 'solution' ) ) {
    		
    		$meta_query = array(
    			array(
    				'key' => 'sponsored',
    				'value' => 'yes',
    				'compare' => 'IN'
    			)
    		);
    		
    		$query->set( 'meta_query', $meta_query );
    		$query->set( 'orderby', 'meta_value' );
    		$query->set( 'meta_key', 'sponsored' );
    		$query->set( 'order', 'ASC' );
    		$query->set( 'posts_per_page', '4' );
    		
    		$query->set( 'facetwp', 'true' );
    		
    	}
    
    }
    add_action( 'pre_get_posts', 'solution_directory' );

    I’m trying this sort of thing, but I know that I’m not reaching the sponsored field through the relationship with this.