• Resolved gottfrieds

    (@gottfrieds)


    On the page are two widgets: Aktuelles für diese Kita

    The first one uses the shortcode [su_posts …. It shows a link to a post.

    Th second one (dyn SC) generates the same shortcode with this code:

    add_shortcode( 'kitaposts', function ($attr) { 
       $kita_sw = get_post_meta( get_the_ID(), 'kita_ID', true );
      $shc = '[su_posts template="templates/list-loop.php" posts_per_page="10" taxonomy="post_tag" tax_term="' . $kita_sw . '"]';
      echo 'Shortcode: ' . $shc . '<br>';
      do_shortcode($shc);
      }
    );

    This gives no result. Where do I make an error????

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Shortcode functions return content as a string, they don’t echo it.

    The shortcode function should return the data, not call do shortcode to immediately echo it to the page.

    A shortcode function is like a filter. They take the shortcode, and return the string to replace that shortcode in the content.

    Thread Starter gottfrieds

    (@gottfrieds)

    Thank you for the answer. How can I reach the intended effect??

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    How can I reach the intended effect??

    Don’t do any “echo” in the shortcode function. Don’t do “do_shortcode” either.

    Build the string, and return it. This isn’t that complicated.

    Thread Starter gottfrieds

    (@gottfrieds)

    Thanks, but sorry to disturb you once more. Now I use this code:

    add_shortcode( 'kitaposts', function () { 
      $kita_sw = get_post_meta( get_the_ID(), 'kita_ID', true );
      $shc = "[su_posts template='templates/list-loop.php' posts_per_page='10' taxonomy='post_tag' tax_term='" . $kita_sw . "']";
      return $shc;
      }
    );

    And it’s the same effect. The shortcode is outputed instead of executed. You can see it on the linked page.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Yes, having a shortcode return a shortcode isn’t going to work. It doesn’t process them recursively.

    Call the other shortcode function with the arguments directly instead of trying to build a shortcode from within another shortcode.

    Thread Starter gottfrieds

    (@gottfrieds)

    I wrote a function doing the work. Now it works. Thanks for your hints.

    I really appreciate that a www.ads-software.com admin hes replied to this post with ZERO to add.

    Maybe show an example of what you are saying for the rest of the internet to use. In this example, it is as simple as a string. What about other examples that require a more complex shortcode to be triggered inside of the one you are creating? If there is no contribution to this progress, why even keep this post up? just to annoy people actually searching for an answer?

    how do i do this? oh you cant, thanks i did it another way… zero examples, zero code showing the solution.. are you kidding me?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘shortcode with do_shortcode() within widget’ is closed to new replies.