Support » Plugin: Related Posts by Taxonomy » Related posts by TAGS (Non standard using)

  • Resolved Goajazzz

    (@goajazzz)


    Hi there! I trying to integrate this plugin with Elementor page builder and I succeed to display related posts from this plugin in elementor widget – the code is below:

    add_action( 'elementor_pro/posts/query/lwp_related_posts', 'lwp_3266_related_posts' );
    function lwp_3266_related_posts( $query ) {
        global $post;
        $query->set(
            'post__in',
            km_rpbt_get_related_posts(
                $post->ID,
                array( 'fields' => 'ids' )
            )
        );
    }

    But I can’t realize how to show posts only by tags or only by categories?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author keesiemeijer

    (@keesiemeijer)

    Hi Goajazzz

    Try it with this in your (child) theme’s functions.php file.

    
    add_action( 'elementor_pro/posts/query/lwp_related_posts', 'lwp_3266_related_posts' );
    function lwp_3266_related_posts( $query ) {
        global $post;
        $query->set(
            'post__in',
            km_rpbt_get_related_posts(
                $post->ID,
                array( 'fields' => 'ids', 'taxonomies' => array('post_tag') )
            )
        );
    }
    

    For more information about the function parameters see:
    https://keesiemeijer.github.io/related-posts-by-taxonomy/functions/km_rpbt_get_related_posts

    btw:
    consider creating a child theme instead of editing your theme directly – if you upgrade the theme all your modifications will be lost. Or create a plugin with the code above.

    Goajazzz

    (@goajazzz)

    Thank you keesiemeijer, you’re rock!

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