What is the Correct way to pass parameters in function

The following is problematic in the OP’s code snippet: Missing shortcode_atts() for default attribute handling. Incorrectly defining the shortcode’s input argument, use instead function create_my_shortcode( $attr = [], $content = null ){ … } Not escaping user input, check e.g. wpdb::prepare(). We want to avoid possible SQL injections. Uses hardcoded table prefix, wp_, instead of … Read more

Shortcode is running in page editor

Thanks to @mmm I figured it out. What I am doing now is adding the form in between php tags. EXAMPLE of what I was doing ?> <input type=”checkbox” name=”overwrite” value=”true”>Overwrite?<br> <?php What I need to be doing is adding the content that I want to add to the page into a string that is … Read more

Shortcode “post_per_page” not working

You have the posts_per_page attribute in your shortcode, but you’re not actually calling it in your WP_Query. Your’re doing a few unnecessary things in your code, but for now, the issue at hand is that you need to add: if( !empty( $posts_per_page )) { $query .= ‘&posts_per_page=”.$posts_per_page; } Before you call: $wp_query->query($query); As it is … Read more

Get URL Param Plugin and Inserting Result in Widget Code

I think the underlying issue here is that shortcodes are not evaluated when placed inside HTML attributes. You could modify the template and output the necessary HTML using PHP and do_shortcode( ‘[urlparam param=”Book” /]’) as an alternative approach: <!– Calendly inline widget begin –> <div class=”calendly-inline-widget” data-url=”<?php echo do_shortcode( ‘[urlparam param=”Book” /]’ ); ?>” style=”min-width:320px;height:580px;”></div> … Read more

How do I debug a short code?

From reading this guide, could you try using a variable to output the return as such? $output=”This is the return”; return $output; Also, if you’re calling the shortcode with do_shortcode(‘[michael]’); in a php file, you’ll need to echo this, like so: <?php echo do_shortcode(‘[michael]’); ?>

Passing a nested shortcode as an argument of another shortcode?

A partial solution I’ve found so far is to escape the brackets in the initial call, then replace the escaped characters in the do_foo_shortcode function. function do_foo_shortcode($atts, $content = null) { extract(shortcode_atts(array( ‘bar’ => ”, ), $atts, ‘foo’)); $bar = str_replace(“&#091;”, “[“, $bar); $bar = str_replace(“&#093;”, “]”, $bar); $bar = do_shortcode($bar); $content = do_shortcode($content); return … Read more

WordPress Shortcode show database row

I’m not entirely sure if that’s what you wanted, but… Here’s the code that will register a shortcode, which will get given row and output all the fields of it: function shortcode_db_row_cb( $atts ) { $atts = shortcode_atts( array( ‘id’ => false, ), $atts, ‘db_row’ ); global $wpdb; $row = $wpdb->get_row( $wpdb->prepare( “select * from … Read more

Different uniqid when calld in wp_localize_script and shortcode

Inside the __construct() you can put this global $shortcode_id; $shortcode_id = 0; in the display_gallery_shortcode() function you can do this <?php global $shortcode_id; $shortcode_id ++; $settings_arr = array();//Here is your settings for each shortcode ob_start(); ?> <script> if(!my_plugin_data) var my_plugin_data = {} my_plugin_data[<?php echo $shortcode_id ?>] = <?php echo json_encode($settings_arr) ?> </script> <div>MY SHORTCODE CONTENT … Read more

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