Title: Use plugin function in custom WP_Query
Last modified: September 15, 2016

---

# Use plugin function in custom WP_Query

 *  Resolved [imcobarn](https://wordpress.org/support/users/imcobarn/)
 * (@imcobarn)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/use-plugin-function-in-custom-wp_query/)
 * Hi,
 * Is there a way to make a WP_Query that uses plugin shortcode?
    Maybe like: $the_query
   = new WP_Query(km_rpbt_related_posts_by_taxonomy( $post_id , ‘category’, $args));
   OR $the_query = new WP_Query([related_posts_by_tax exclude_terms=”20,23,14″]);
 * Not sure if that would work.
 * I saw this on your page at [https://keesiemeijer.wordpress.com/related-posts-by-taxonomy/#shortcode](https://keesiemeijer.wordpress.com/related-posts-by-taxonomy/#shortcode)
   but that just seem to add post ID:
 * // example query
    $the_query = new WP_Query(‘cat=3’);
 * // add this right after the query
    // use the query object ($the_query) to check
   if posts are found $the_query_id = ( isset( $the_query->post->ID ) ) ? $the_query-
   >post->ID : 0; set_query_var( ‘km_rpbt_related_post_id’, $the_query_id );
 * Thank you so much.

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

 *  Plugin Author [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/use-plugin-function-in-custom-wp_query/#post-8189573)
 * Hi imcobarn
 * What is it you want to do? Mix a custom query with the related posts query?
 * Or do you want to get the post objects from this query?
 *     ```
       [related_posts_by_tax exclude_terms=”20,23,14″]
       ```
   
 *  Thread Starter [imcobarn](https://wordpress.org/support/users/imcobarn/)
 * (@imcobarn)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/use-plugin-function-in-custom-wp_query/#post-8190230)
 * Hi,
 * Yes I would like to just get the post objects with the shortcode because I have
   custom display for the posts after `if ( $the_query->have_posts() ) :`
 * So I would retrieve related posts using your plugin but display them in my loop.
 * Thank you so much.
 *  Plugin Author [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/use-plugin-function-in-custom-wp_query/#post-8191983)
 * You can display the related posts like this in your template:
 *     ```
       <?php echo do_shortcode( '[related_posts_by_tax exclude_terms="20,23,14"]' ); ?>
       ```
   
 * Or use the `km_rpbt_related_posts_by_taxonomy()` function. See this example:
   
   [https://keesiemeijer.wordpress.com/related-posts-by-taxonomy/functions/#examples](https://keesiemeijer.wordpress.com/related-posts-by-taxonomy/functions/#examples)
    -  This reply was modified 9 years, 8 months ago by [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/).

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

The topic ‘Use plugin function in custom WP_Query’ 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

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

 * 3 replies
 * 2 participants
 * Last reply from: [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * Last activity: [9 years, 8 months ago](https://wordpress.org/support/topic/use-plugin-function-in-custom-wp_query/#post-8191983)
 * Status: resolved