Title: Shortcode works, do_shortcode or theme functions do not
Last modified: October 24, 2017

---

# Shortcode works, do_shortcode or theme functions do not

 *  Resolved [kontur](https://wordpress.org/support/users/kontur/)
 * (@kontur)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/shortcode-works-do_shortcode-or-theme-functions-do-not/)
 * Hey,
 * when I use the shortcode in the end of a post the plugin correctly renders some
   related posts.
 * However, when I try to integrate the shortcode to my article template, neither
   do_shortcode() nor km_rpbt_related_posts_by_taxonomy() seem to work (for the 
   same exact post). Inside the loop I have tried both of these like so:
 *     ```
       <?php var_dump($post->ID); ?>
       <?php do_shortcode('[related_posts_by_tax post_id="' . $post->ID . '"]'); ?>
       <?php km_rpbt_related_posts_by_taxonomy($post->ID, 'category'); ?>
       ```
   
 * I get the correct post ID output to the page, but no related posts or errors.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/shortcode-works-do_shortcode-or-theme-functions-do-not/#post-9615359)
 * Hi kontur
 * Are you echoing the shortcode?
 *     ```
       <?php echo do_shortcode('[related_posts_by_tax post_id="' . $post->ID . '"]'); ?>
       ```
   
 *  Thread Starter [kontur](https://wordpress.org/support/users/kontur/)
 * (@kontur)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/shortcode-works-do_shortcode-or-theme-functions-do-not/#post-9615371)
 * *facepalm* Thanks, solved 🙂
 * Very nice plugin, thank you for the work!
 *  Plugin Author [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/shortcode-works-do_shortcode-or-theme-functions-do-not/#post-9615381)
 * You’re welcome 🙂
 *  [wadehammes](https://wordpress.org/support/users/wadehammes/)
 * (@wadehammes)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/shortcode-works-do_shortcode-or-theme-functions-do-not/#post-10131522)
 * The shortcode works for me, but the function is returning an empty array:
 *     ```
       $taxonomies = array('project_categories', 'service_categories');
       $has_related = km_rpbt_related_posts_by_taxonomy($post->ID, $taxonomies);
       ```
   
 * a `var_dump` of the function gives me:
 *     ```
       array(0) {}
       ```
   
 * Any thoughts?
 * —-
 * I needed to pass the correct post type in the args. Nevermind 🙂
    -  This reply was modified 8 years, 2 months ago by [wadehammes](https://wordpress.org/support/users/wadehammes/).
    -  This reply was modified 8 years, 2 months ago by [wadehammes](https://wordpress.org/support/users/wadehammes/).

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Shortcode works, do_shortcode or theme functions do not’ is closed to
new replies.

 * ![](https://ps.w.org/related-posts-by-taxonomy/assets/icon.svg?rev=1115231)
 * [Related Posts by Taxonomy](https://wordpress.org/plugins/related-posts-by-taxonomy/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/related-posts-by-taxonomy/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/related-posts-by-taxonomy/)
 * [Active Topics](https://wordpress.org/support/plugin/related-posts-by-taxonomy/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/related-posts-by-taxonomy/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/related-posts-by-taxonomy/reviews/)

## Tags

 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)
 * [template](https://wordpress.org/support/topic-tag/template/)

 * 4 replies
 * 3 participants
 * Last reply from: [wadehammes](https://wordpress.org/support/users/wadehammes/)
 * Last activity: [8 years, 2 months ago](https://wordpress.org/support/topic/shortcode-works-do_shortcode-or-theme-functions-do-not/#post-10131522)
 * Status: resolved