Support » Plugins and Hacks » [Plugin: Get Custom Field Values] Empty widget shows up

[Plugin: Get Custom Field Values] Empty widget shows up

  • Hi there,

    first thanks a lot for this plugin. It was exactly what I searched for.
    Although I still have one suggestion for making me 100% happy 🙂

    I have some posts with custom-fields that should show up in the sidebar (e.g. see http://www.klaviernoten4u.de/river-flows-in-you/ the right top-widget is from the custom-field “sidebar”)
    But I have other posts (currently all others 🙂 that doesn’t have the custom-field “sidebar” defined and nothing should be displayed in the sidebar.
    The widget is therefore configured with
    Post-ID = 0
    Custom field key = sidebar

    Everything else is empty.

    Nevertheless even though there is nothing to be shown the widget shows up (it is displayed emtpy). The $before_widget and $after_widget is rendered and so you see an empty widget-box.

    My proposal would be this:
    In get-custom-field-values/get-custom.widget.php the method widget_body should return the result (and not echo it):

    function widget_body( $args, $settings, $instance ) {
    if ( 'current' == $post_id )
    return c2c_get_current_custom( $field, $before, $after, $none, $between, $before_last );
    elseif ...

    and in

    get-custom-field-values/c2c-widget.php in method widget (where widget_body is called) instead of

    echo $before_widget;

    if ( ! empty( $title ) )
    echo $before_title . $title . $after_title;

    $this->widget_body( $args, $instance, $settings );

    echo $after_widget;

    I would suggest these changes:

    $body = $this->widget_body( $args, $instance, $settings );

    if ( strlen( trim( $body) ) ) {
    echo $before_widget;
    if ( ! empty( $title ) )
    echo $before_title . $title . $after_title;
    echo $body . $after_widget;

    That avoids showing up empty widgets. And it avoids a title to be displayed if there is no body.

    Thanks again and hope it helps and wish this could be inserted in a future release.


Viewing 1 replies (of 1 total)
  • Plugin Author Scott Reilly


    WordPress & Plugin Developer

    Great suggestion! You can definitely expect to have this in v3.4 of the plugin, which should be out soon. Thanks!

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Get Custom Field Values] Empty widget shows up’ is closed to new replies.