WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Widget
[resolved] Content Block inserting All-in-One Event data (6 posts)

  1. thinguy
    Member
    Posted 2 years ago #

    Content block is working fine putting content into a sidebar.
    But when I go to an Event from 'All-in-One Event Calendar' it pulls a duplicate of the event main content into the content block area.
    On other pages the same content block works fine.

    Please let me know what info I can provide, I'm running on a WAMP install for Dev

    http://wordpress.org/extend/plugins/custom-post-widget/

  2. -creynolds-aiec
    Member
    Posted 2 years ago #

    Having this exact same issue. I can hide it with css but that is a pretty janky solution.

  3. brendaegeland
    Member
    Posted 2 years ago #

    Same problem ... I think it is because Custom Post Widget doesn't do an actual WP_Query to get the content for the widget. Rather, it retrieves the content and runs it through the filters and shortcodes, trying to mimic what the_content() does. However, some filters are specific to a post type (e.g., the events for All-in-One Event Calendar) and they are getting erroneously applied to the content_block content.

    I have modified function widget in post-widget as shown below and it seems to be working for me in my particular case. ymmv...


    function widget($args, $instance) {
    extract($args);
    $custom_post_id = ( $instance['custom_post_id'] != '' ) ? esc_attr($instance['custom_post_id']) : __('Find', 'custom-post-widget');
    // Variables from the widget settings.
    $show_custom_post_title = isset( $instance['show_custom_post_title'] ) ? $instance['show_custom_post_title'] : false;
    $content_post = get_post($custom_post_id);
    $content = $content_post->post_content;

    /* NEW */
    global $post;
    $tmp = $post;
    $args = array(
    'p' => $custom_post_id,
    'post_type' => 'content_block'
    );
    $the_query = new WP_Query( $args );

    echo $before_widget;
    while ( $the_query->have_posts() ) : $the_query->the_post();
    if ($show_custom_post_title) {
    echo $before_title . the_title() . $after_title;
    }
    the_content();
    endwhile;
    echo $after_widget;

    $post = $tmp;

    /* END NEW */
    /* OLD */
    /*
    $content = apply_filters('the_content', $content);
    echo $before_widget;
    if ( $show_custom_post_title ) {
    echo $before_title . $content_post->post_title . $after_title; // This is the line that displays the title (only if show title is set)
    }
    echo do_shortcode($content); // This is where the actual content of the custom post is being displayed
    echo $after_widget;
    */
    /* END OLD */
    }

    }

  4. brendaegeland
    Member
    Posted 2 years ago #

    Update ... the two lines before /* NEW */ aren't needed and should be moved into the commented out /* OLD */ block ...

  5. Johan van der Wijk
    Member
    Plugin Author

    Posted 2 years ago #

    This is actually caused by the fact that the All-in-One Event Calendar does not check when to insert the event data.

    You can point the developer of the All-in-One Calendar to this post which describes how to properly use the the_content filter: http://pippinsplugins.com/playing-nice-with-the-content-filter/

  6. Johan van der Wijk
    Member
    Plugin Author

    Posted 2 years ago #

    The latest version of the Custom Post Widget plugin now has the option to disable apply_filters on the_content which should solve this issue.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic