• Resolved imcobarn

    (@imcobarn)


    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 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

    (@keesiemeijer)

    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

    (@imcobarn)

    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

    (@keesiemeijer)

    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

    • This reply was modified 8 years, 5 months ago by keesiemeijer.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Use plugin function in custom WP_Query’ is closed to new replies.