Last active
April 30, 2023 16:33
-
-
Save l00f00/e5e715984eaa632a97975f04cfb208da to your computer and use it in GitHub Desktop.
exclude from query oxygen easypost/repeater
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add "Code Block" oxygen element. | |
This Code block has to be placed BEFORE the "Easy Post" element. | |
___________________________________________________________________________________single post | |
/** | |
* Exclude Current Posts from the query | |
*/ | |
add_action( 'pre_get_posts', function ( $query ) { | |
// not an admin page and not the main query | |
if ( ! is_admin() && ! $query->is_main_query() ) { | |
$query->set( 'post__not_in', array( get_the_ID() ) ); | |
} | |
} ); | |
__________________________________________________________________________________Homepage | |
add_action( 'pre_get_posts', function ( $q ) | |
{ | |
if ( !is_admin() // Not necessary for home page, included it to be used on any other template like category pages | |
&& $q->is_main_query() // Make sure this is the main query | |
&& $q->is_home() // Targets the home page only | |
) { | |
if ( function_exists( 'get_sticky_category_posts' ) ) { | |
$args = [ | |
0 => ['posts_per_page' => 5, 'taxonomy' => 'category', 'included_terms' => 3, 'excluded_terms' => 9], | |
1 => ['posts_per_page' => 5, 'taxonomy' => 'category', 'included_terms' => 4, 'excluded_terms' => 9], | |
]; | |
$sticky_cat_posts = get_sticky_category_posts( $args ); | |
if ( !empty( $sticky_cat_posts ) ) { | |
$q->set( 'post__not_in', $sticky_cat_posts ); | |
} | |
} | |
} | |
}); | |
________________________________________________________________________________Generic easy post | |
<?php | |
function cut_query( $query ) { | |
if ( ! is_admin() && ! $query->is_main_query() ) { | |
$query->set('posts_per_page', 1); | |
$query->set( 'offset',9 ); | |
} | |
} | |
add_action( 'pre_get_posts', 'cut_query' ); | |
?> | |
///EASY POST | |
<?php | |
remove_action( 'pre_get_posts', 'cut_query'); | |
?> | |
________________________________________________________________________________Offset grid builder + easyposts | |
____________________________________________________________________________________________with code snippets | |
__________oxygen-element-55, 8 is the “ID” of Repeater/easypost as it appears in the Structure panel in editor. | |
<?php | |
//offset news&events grid-builder | |
add_action( | |
'pre_get_posts', | |
function( $query ) { | |
$offset = 13; | |
$ppp = 4; | |
if ( 'oxygen-element-55' === $query->get( 'wp_grid_builder' ) ) { | |
$query->set('posts_per_page', $ppp); | |
$query->set( 'offset', $offset ); | |
} | |
}, | |
PHP_INT_MAX - 10 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment