How to handle Ajax Calls, when using same shortcodes (with different parameters, e.g. ‘post-type’)?

The problem is that your JS needs to know the post type for each shortcode, but rather than looking at the shortcodes output, it looks at the main global kne_ajax_object, and since there is only one kne_ajax_object, there can only be one post type. Additionally, your javascript code only runs one time, and only makes … Read more

Using variable as shortcode parameter

The shortcode function behind that shortcode will need to be able to accept an argument so it can return your variable in the expected place. If this is a custom shortcode function you wrote, you’ll have to make that adjustment. If its a third party shortcode, you’ll need to look at their documentation and see … Read more

How to pass text input data to shortcode

You would need to do this in the shortcode function for [api_request]. Here’s a potential answer with a ternary that would check if the $_POST value exists, if so, sanitize and use it, otherwise use the value passed in the shortcode: $q = ( isset( $_POST[‘q’] ) ) ? sanitize_text_field( $_POST[‘q’] ) ? $atts[‘q’]; This … Read more

Executing a shortcode at the top of PAGE template?

The do_shortcode function accepts a string, searches the string for shortcodes, and processes any that are found. That means that… // Use shortcode in a PHP file (outside the post editor). echo do_shortcode(”); … is all you need to run a shortcode (code taken from the Codex). Your request that the shortcode be inserted “somewhere … Read more

How to reuse php templates as shortcodes?

You can write a wrap function for short code like that. function simplest_shortcode_ever() { ob_start(); ?> Your PHP Logic here <?php return ob_get_clean(); } add_shortcode( ‘simple_shortcode’, ‘simplest_shortcode_ever’ ); And then use it[simple_shortcode]

filter custom field with checkboxes and show it with one shortcode

add_shortcode( “Querbett”, “bettenaert”); add_shortcode( “Alkovenbett”, “bettenaert”); add_shortcode( “Queensbett”, “bettenaert”); add_shortcode( “Hubbett”, “bettenaert”); function bettenaert ( $atts, $content = null, $tag ) { modell_nach_bettenart_2( $tag ); } Now use shortcode [Querbett], [Alkovenbett], [Queensbett] or[Hubbett] as required. I hope this may help.