We're merging with GenerateBlocks! Learn more here.

[Resolved] snippet to convert a shortcode

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support snippet to convert a shortcode

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #31631
    Carlo
    Participant

    Hi all,

    since there is a problem with & converted into & amp ; (wihout spaces) in gutenberg shortcodes and html blocks as well, in a generatepress forum’s thread (this is the link https://generatepress.com/forums/topic/turning-into-in-shortocodes/#post-1840249)

    David suggested me to refer to the following post in this forum https://wpshowposts.com/support/topic/category-specific-side-bar/#post-31332

    What would the snippet code be providing that my aim is to reproduce this shortcode?
    [wp_show_posts id=”10150″ settings=”meta_key=id_number&orderby=meta_value&order=ASC”]

    Thank you. All the best. Carlo

    #31650
    elvin
    Moderator

    Hi Carlo,

    Try this:

    add_shortcode('dynamic_wpsp', function($atts){
        $queriedArchive = get_queried_object();
        $atts = shortcode_atts( array(
    			'id' => ''
    		), $atts, 'dynamic_wpsp' );
    
        $settings = array(
            'order'      => 'ASC',
            'orderby'  => 'meta_value',
            'meta_key'  => 'id_number',
        );
     
        ob_start();
        wpsp_display( $atts['id'], $settings );
        return ob_get_clean();
    });
    #31687
    Carlo
    Participant

    Thank you Elvin, it works.

    Just in case someone else should need it, I just added the id number of the list here (ie: 1234)

    ‘id’ => ‘1234’

    #31703
    elvin
    Moderator

    Ah yes that’s right I forgot to mention the shortcode attributes. My bad.

    Yes you need to specify that. Else, the shortcode wouldn’t know which to call. Example: [dynamic_wpsp id="80210"]

    Glad you got it sorted. No problem. 😀

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.