somehow Events Calendar Pro is breaking my WP_Query

Home Forums Calendar Products Events Calendar PRO somehow Events Calendar Pro is breaking my WP_Query

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #159484
    Davide
    Participant

    I am trying to put some “related posts” into my single-post.php.
    I am setting WP_Query with ‘post_type’ => ‘post’ , but somehow the query is executed with ‘post_type’ => array(‘post’,’tribe_events’).
    AAARGHHH this is driving me crazy…

    #160118
    Barry
    Member

    Hi – I’m sorry you’re facing difficulties here.

    Though the amount of help we can offer with custom code is admittedly limited we might be able to offer a pointer in the right direction.

    Can you provide a little more detail though? What is the actual code you have put in place (if you can share via a link to Pastebin/Gist/similar that would be great) and when and how is it called?

    Thanks!

    #160360
    Davide
    Participant

    Hi Barry,
    thank you for your reply… here is my code: http://pastebin.com/fqanAnyb
    This code is from my functions.php, and I call rm_related_posts(get_the_ID()); in my single-post.php.
    Uncommenting line 21-22-23, I can see that somehow WP_Query has been modified adding ‘tribe_events’ to the ‘post_type’ parameter.
    DV

    #160681
    Barry
    Member

    Thanks!

    Yes, that ‘s exactly what happens (the event post type is added to the query) as events also make use of regular post tags – so this is actually expected behaviour. What you could do though is also define the following functions:

    function stick_to_posts() {
    	add_action( 'parse_query', 'force_post_type_to_posts', 60 );
    }
    
    function force_post_type_to_posts( $query ) {
    	remove_action( 'parse_query', 'force_post_type_to_posts', 60 );
    	$query->set( 'post_type', array( 'post' ) );
    }

    Then, at the top of your rm_related_posts() function (right above $tags = wp_get_post_tags($post_id)) add:

    stick_to_posts();

    Does that help with this?

    #160740
    Davide
    Participant

    GRANDE Barry! It worked.
    Thank you so much!

    #162218
    Barry
    Member

    Awesome, happy to help!

    I’ll go ahead and close this thread – but if we can help with anything else please don’t hesitate to create new threads as needed … also – if you have a moment and wanted to leave a review, that would be great – we always love to hear about people’s experiences with The Events Calendar 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘somehow Events Calendar Pro is breaking my WP_Query’ is closed to new replies.