Pass javascript array to shortcode

You’re going to have other problems than the brackets because shortcode_parse_atts will have already parsed your attributes, and the various single and double quotes will confuse the regular expression used to do that. If you need the exact string, perhaps you could get it from a custom field. Alternatively, and better, you could specify a … Read more

Can wp_localize_script be used within a shortcode?

Default parameters for wp_enqueue_script will output the script in the wp_head function. Shortcodes typically execute later, when main content is being output. In that case, calling wp_localize_script in the Shortcode handler will have no effect, because the script has already been output. Setting the $in_footer parameter to true when enqueueing the script will delay script … Read more

How to return a foreach inside a shortcode

As I said in the comment you can use buffering like this function stock_agenda() { $days = json_decode(file_get_contents(‘json_file’)); unset($days[0]); ob_start(); // start buffer ?> <table class=”table”> <thead> <tr> <th> Title </th> <th>Content</th> <th>Date</th> </tr> </thead> <tbody> <?php foreach($days as $day) { ?> <tr> <td><?php echo $day[0]; ?></td> <td><?php echo $day[1]; ?></td> <td><?php echo $day[2]; ?></td> … Read more

Adding shortcode closing tag after a loop

Collect all of the loop’s output in a variable, wrap it in the accordion shortcode, then pass that through do_shortcode: $output=””; if ( have_posts() ) : while ( have_posts() ) : the_post(); $output .= ‘<div class=”col-lg-12 col-md-12 col-sm-12 col-xs-12″>’; $output .= do_shortcode(‘[su_spoiler title=”‘.get_the_title().'” open=”no” style=”default” icon=”plus” anchor=”” class=””]’.get_the_content().'[/su_spoiler]’); $output .= ‘</div>’; endwhile; else : $output … Read more

WP_Query is printing out only one post when posts_per_page is set to multiple

you are re-initializing the out variable that is why it shows only one product // Custom Post Type for Use Cases page slider function create_post_type() { register_post_type( ‘use_cases’, array( ‘labels’ => array( ‘name’ => __( ‘Use Cases’ ), ‘singular_name’ => __( ‘Use_Case’ ) ), ‘public’ => true, ‘has_archive’ => true, ) ); } add_action( ‘init’, … Read more

How to limit the content coming from wordpress shortcodes?

It’s better to 1st save the returned XML to a file and then loop back to unset. <?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => “http://www.cpac.ca/tip-podcast/jwplayer.xml”, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => “”, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => “GET”, CURLOPT_HTTPHEADER => array( “cache-control: no-cache”, “postman-token: 28025ee8-1e82-ce60-f6ae-f401118baa1c” ), )); $response = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)