Shortcode argument multiple values

It depends on the plugin. WordPress does not natively support passing multiple values to a shortcode attribute. The value you’re passing to the shortcode is simply ‘1,2’. How that value is handled depends entirely on how the shortcode was implemented by the developer.

How do I define and register a shortcode function in a namespaced functions.php file?

Thanks to Stanislav Khromov (also active on WPSE!), I learned any Callable referenced in add_shortcode() must be fully qualified, even if it is defined in the same file you’re referencing it. <?php /** * theme’s functions.php */ namespace MyNamespace; //[foobar] function foobar_func( $atts ){ return “foo and bar”; } add_shortcode( ‘foobar’, ‘\MyNamespace\foobar_func’ ); You may … Read more

Wp-query Order By problem

The “problem” seems to be the default value that order receives, its always DESC unless told otherwise. You will need to create your own order after getting the posts, so something like this. $my_query = new WP_Query($query_args); $ordered_posts = []; foreach(explode(‘,’, $idpaginas) as $rpid) { foreach($my_query->posts as $index => $fpid) { if($fpid->ID == $rpid) $ordered_posts[] … Read more

calling a custom field value inside functions.php

if you’re not planning on adding much html there is no need to use ob_start just return the php: function wpb_description_shortcode( ){ if (get_post_meta(get_the_ID(), ‘song_number’, true)) { return get_post_meta(get_the_ID(), ‘song_number’, true).'<br/>’; } else { return; } } // Register shortcode add_shortcode(‘my_description_number’, ‘wpb_description_shortcode’); I’m not sure what this data is, but it would be a good … Read more

How can I add a shortcode to query Custom Post Type with ACF in WordPress?

I ultimately figured out getting a shortcode to work by reworking the code to the following: add_shortcode( ‘gr_shortcode’, ‘gr_shortcode’ ); function gr_shortcode() { $buffer=”<h3>Upcoming Titles</h3>”; $q = new WP_Query(array( ‘post_type’ => ‘game_release’, ‘posts_per_page’ => 3 )); while ($q->have_posts()) { $q->the_post(); $buffer = $buffer.get_the_title().'<br>’.$buffer.the_field(‘release_date’); } wp_reset_postdata(); return $buffer; }

When are Shortcode Attributes Available in Template

I need access to the shortcode attributes before the content (and it’s shortcode) is processed…. in the first “is $atts available here” after the add_shortcode In that case, you can manually parse the shortcode and retrieve its attributes (if any) like so, which uses get_shortcode_regex() and shortcode_parse_atts(): $content=”before blah2 [foo bar=”baz” num=”123″] after”; preg_match( “https://wordpress.stackexchange.com/” … Read more

Adding custom form within add_shortcode

whenever I paste the shortcode in the page editor the form posts automatically and redirects to /wp-admin/admin-post.php with a blank screen I don’t know what editor is that (🤔), and I’m not sure if this will fix the above issue, but I noticed your function is using wp_nonce_field() which by default displays/echo the output, so … Read more

How to echo the value of an array element using a function via a shortcode

I do not understand this response unfortunately. I don’t know how to take this, and turn it into working code. What I meant by that response, is that you would be using a shortcode that looks like these in your posts: [print-price key=”price1″] [print-price key=”price2″] [print-price key=”foo-bar”] Where key is an attribute for the shortcode … Read more