Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'posts_results', 'insert_post_wpse_96347', 10, 2 );
- function insert_post_wpse_96347( $posts, \WP_Query $q ) {
- remove_filter( current_filter(), __FUNCTION__ );
- if ( $q->is_main_query() && $q->is_home() && 0 == get_query_var( 'paged' ) ) {
- $args_uno = [
- 'meta_key' => 'caja',
- 'meta_value' => 'uno',
- 'post__not_in' => get_option( "sticky_posts" ),
- 'posts_per_page' => '1',
- 'status' => 'publish',
- 'suppress_filters' => true
- ];
- $args_dos = [
- 'meta_key' => 'caja',
- 'meta_value' => 'dos',
- 'post__not_in' => get_option( "sticky_posts" ),
- 'posts_per_page' => '1',
- 'status' => 'publish',
- 'suppress_filters' => true
- ];
- $p1insert = new WP_Query($args_uno);
- $p2insert = new WP_Query($args_dos);
- if ( !empty( $p2insert->posts ) ) {
- array_splice( $posts, 0, 0, $p1insert->posts );
- array_splice( $posts, 1, 0, $p2insert->posts );
- }
- }
- return $posts;
- }
- function cmp_exclude_featured_posts($query) {
- $exclude = array(); //Create empty array for post ids to exclude
- if ( $query->is_main_query() && $query->is_home()) {
- $featured = get_posts(array(
- 'post_type' => 'post',
- 'posts_per_page' => 2,
- 'meta_query' => array(
- array(
- 'key' => 'caja',
- 'value' => array('uno','dos')
- ),
- ),
- ));
- foreach($featured as $hide) {
- $exclude[] = $hide->ID;
- }
- $query->set('post__not_in', $exclude);
- }
- }
- add_filter( 'pre_get_posts', 'cmp_exclude_featured_posts' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement