Created
September 15, 2022 09:52
-
-
Save giucu91/01f532f3f4038ca40390a6d172dd5328 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
public function add_query_args__current( $args, $atts ) { | |
/* | |
* The query does not change if the current post type or the specific post is excluded. | |
*/ | |
if ( wpmtst_assignment_is_post_excluded( get_the_ID() ) ) { | |
return $args; | |
} | |
/* | |
* Single post or page | |
*/ | |
if ( is_single() || is_page() ) { | |
$args['meta_key'] = 'strong_assignment'; | |
$args['meta_value'] = get_the_ID(); | |
return $args; | |
} | |
/* | |
* Archives | |
*/ | |
if ( ( is_post_type_archive() || is_category() || is_tax() || is_home() ) && in_the_loop() ) { | |
$args['meta_key'] = 'strong_assignment'; | |
$args['meta_value'] = get_the_ID(); | |
return $args; | |
} | |
if ( ( is_post_type_archive() || is_category() || is_tax() || is_home() ) && ! in_the_loop() ) { | |
// get the IDs of all posts being displayed | |
global $posts; | |
$post_list = array(); | |
foreach ( $posts as $post_object ) { | |
$post_list[] = $post_object->ID; | |
} | |
$args['meta_key'] = 'strong_assignment'; | |
$args['meta_value'] = join( ',', $post_list ); | |
$args['meta_compare'] = 'IN'; | |
return $args; | |
} | |
return $args; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment