• When using the widget the content is displayed on the screen using get_post and then the content is put through the “the_content” filter.

    When a plugin hooks into the_content it cannot determine what the other details for the post are, such as the post type. So when a plugin wants to add something for only one post type it will fail.

    Would it be possible to use the loop for displaying the content block? So either using $custom_query = new WP_Query(); $custom_query->the_post() or using setup_postdata

    https://wordpress.org/plugins/custom-post-widget/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Johan van der Wijk

    (@vanderwijk)

    Hi Anton,

    Initially I was using the loop but because of many issues with social sharing and event management plugins that add content to anywhere they see the loop I changed this to get_post.

    Another advantage of using get_post is that this should be faster.

    Could you provide me with a specific scenario for which you need the loop? I could see if there is anything I can do about your issue.

    Thread Starter Anton Timmermans

    (@atimmer)

    The actual point where it is going wrong is when using a social media plugin.

    The social media plugin uses the the_content filter to add the social media buttons. In the code for adding the social media buttons there is code comparable like this:

    if ( is_page() ) {
        // Display social media buttons
    }

    The problems occurs when having a sidebar on that page that has the custom post widget in it. the_content filter is called when displaying the custom post but because the global $post variable is still set to a page object (the page we are on) the plugin thinks it should display the social media buttons at the end of the_content filter.

    I don’t think the social media plugin is doing something unreasonable but this might still be a very tricky issue to fix.

    For other people dealing with the same issue, I build a workaround to fix this issue. I added a shortcode to all custom blocks named [hide_social_media_buttons] then I filtered the_content twice, once on priority 9 and once on priority 11. In the first filter I remove the social media button filter if the shortcode is present and in the second filter I re-add the social media button filter if I removed it.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Use the loop in the widget’ is closed to new replies.