How do I amend wp_query before it is run/executed?

Use pre_get_posts to modify the query object before the query has run. – https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts function exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘cat’, ‘-1,-1347’ ); } else if ($query->is_search) { $query->set( ‘s’, ‘stackoverflow’ ); } } add_action( ‘pre_get_posts’, ‘exclude_category’ );

Custom query with meta_key not working fine

@Rod0n WP version 4.2 included the number of improvements in WP_QUERY particularly when use the ‘meta_query’ parameter. Also, check the WP_QUERY Class Refernece. $args = array( ‘post_type’ => ‘proyectos’ , ‘posts_per_page’ => 8 , ‘paged’ => $paged, ‘orderby’ => array( ‘meta_value’ => ‘DESC’ ), ‘meta_query’ => array( array( ‘key’ => ‘wpcf-estado’, ‘compare’ => ‘EXISTS’, ), … Read more

Using wp_query to modify the loop in index.php for a CPT

I would suggest first adding a new file called archive-beach_clean.php to your themes root directory. Then copy and paste all the code from that index file into it. After, if you haven’t done so already, add this argument, ‘has_archive’ => true, to the arguments array used in the register_post_type function and in the same array … Read more