Shortcode arguments to another shortcode

You could pass the variable via a global but it would be neater to trap it in a static variable: function track_acc_id($new_id = false) { static $id; if (!empty($new_id)) { $id = $new_id; } return $id; } //This is the accordion container function accordionGroup( $atts, $content = null ) { extract(shortcode_atts(array( ‘id_container’ => ”, ), … Read more

AJAX and do_shortcode

Ajax runs without a main WP_Query object and therefor all its APIs that are used to determine the type of page that is being displayed. The code which is responsible for outputting the result of the shortcode is probably checking for is_single() to be true so it will not add output to archive pages. What … Read more

Create a function to display HTML/data based on site admins role?

I think below line of code is unnecessary, which is wrong if you looking for logged in user result. if( ! is_user_logged_in() ) Please use below code, I make some changes for solution. //Add a hook for a shortcode ‘add_my_form’ tag… add_shortcode( ‘add_my_form’, ‘get_form_on_role’ ); //Create sortcode API used function… function get_form_on_role() { if(is_user_logged_in() ) … Read more

embedding shortcodes in php template

I think it needs to be like this: <?php $output=”[accordion]”; ?> <?php $args = array( ‘posts_per_page’ => ‘-1’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘category__in’ => $quicksand_categories ); $query = new WP_Query( $args ); foreach ($query->posts as $item) { $categories = wp_get_post_categories($item->ID); ?> <?php $output.='[accordion-item title=”‘.get_the_title($item->ID).'”]’.the_content().'[/accordion-item]’; ?> <?php } ?> <?php $output .= ‘[/accordion]’; ?> … Read more

Pass instance number to shortcode child

You can wrap it in a class. Here’s an example: class WPSE_Answers_Counting { private $instance_answers = 0; private $instance_prev_answers = 0; private $instance_answer = 0; public function init() { add_shortcode( ‘answers’, [ $this, ‘answers_shortcode’ ] ); add_shortcode( ‘ans’, [ $this, ‘answer_shortcode’ ] ); } public function answers_shortcode( $atts = [], $content = null ) { … Read more

tax query shortcode

You just want to make sure you get all your default attributes set in addition to only adding tax queries when you have all the values set. <?php // [loop post_type=”website” taxonomy=”industry” terms=”beauty” posts=”3″][/loop] // [loop post_type=”website” posts=”-1″ ][/loop] function loop_recent_posts_shortcode( $atts ) { $a = shortcode_atts( array ( ‘posts’ => 6, ‘post_type’ => ”, … Read more