-
-
Save billerickson/76261bbdd0dcd5c727c55f581f097734 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 | |
/** | |
* Display Posts Shortcode, support for 'current' category | |
* | |
*/ | |
function be_dps_current_category( $args, $atts ) { | |
if( !empty( $args['category_name'] ) && 'current' == $args['category_name'] ) { | |
$current_categories = get_the_terms( get_the_ID(), 'category' ); | |
if( !empty( $current_categories ) && ! is_wp_error( $current_categories ) ) { | |
$category = array_shift( $current_categories ); | |
$args['category_name'] = $category->slug; | |
} | |
} | |
return $args; | |
} | |
add_filter( 'display_posts_shortcode_args', 'be_dps_current_category', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Bill,
thank you very much for this. Noticed there's a closing bracket missing:
if( !empty( $current_categories ) && ! is_wp_error( $current_categories )
if( !empty( $current_categories ) && ! is_wp_error( $current_categories ))
But that's where my (poor) php skills end. Hence the question: could you extend this to work with all taxonomies like tags, custom posts etc? Tempted to use the shortcode as general loop replacement since it's so convenient.
Thank you
Ronny