Global $post returns 2 objects for my shortcode
Global $post returns 2 objects for my shortcode
Global $post returns 2 objects for my shortcode
As Tom pointed out, the reason you are seeing that error is you shortcode is not returning your desired output, but rather outputting it right in place. This results in a breaking of the REST API and you seeing that error message. Simple fix: function register_form_template_f() { return ‘<h1>Hello World! register</h1>’; } add_shortcode(‘register_form_template’, ‘register_form_template_f’);
Load templates, pass arguments, and render output from functions.php
Sounds like you’re looking for has_category(), which Checks if the current post has any of given category. You would use it, for example in single.php, like so, <?php if ( has_category( array( ‘cat-a’, ‘cat-b’, ‘cat-c’ ) ) ) : ?> <div> <?php echo do_shortcode( ‘some_shortcode’ ); ?> </div> <?php endif; ?>
The $atts in your template part (templates/show-taxonomy.php) that you passed to shortcode_atts() is not defined, so you need to define it by passing it via the third parameter for get_template_part() like this: get_template_part( ‘templates/show-taxonomy’, ”, array( ‘atts’ => $atts ) ); Then in the template part, use $args[‘atts’] to access the shortcode parameters: $atts = … Read more
Can I add Short Code Of A Plugin In The Code Editor of WordPress?
Show in an entry a Custom Post Type associated to a post
Display “no post” message
how I can get the categories from the same global search You can add a taxonomy attribute to your shortcode and then pass the value to get_query_terms_list(), like so: add_shortcode( ‘bd_terms_list’, ‘bd_terms_list_custom_callback’); function bd_terms_list_custom_callback( $args ){ $atts = shortcode_atts( array( // list of default attributes ‘taxonomy’ => ‘gd_place_tags’, ‘sep’ => ”, // optional, but you … Read more
I can’t get the shortcode to work. So I see there’s a $args in your code, so if you actually want posts that match those args, then you can create a secondary query/loop like so: (replace all code from the if (have_posts()) : to the wp_reset_query();): global $post; // Create a secondary query $query = … Read more