Output a Raw Views Loop

Sometimes we need to populate values in as example Select fields (JSON) or of 3rd Party ShortCodes that generate charts or similar.
This snippet allows you to output a given Views Loop without default HTML wrapped around the results.

The following snippet produces a clean View output, or as clean as we can:

add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );

function prefix_clean_view_output( $out, $id ) {
if ( $id == '375' ) {
$start = strpos( $out, '<!-- wpv-loop-start -->' );
if ( 
$start !== false
&& strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false
) {
$start = $start + strlen( '<!-- wpv-loop-start -->' );
$out = substr( $out , $start );
$end = strrpos( $out, '<!-- wpv-loop-end -->' );
$out = substr( $out, 0, $end );
}
}
return $out;
}

Use a Views Loop similar to the below:

Bildschirmfoto 2015-11-04 um 19.10.47

Step by step:

  • It hooks early in the View output.
  • Priority 5 is mandatory as we already do some other cleaning at priority 10.
  • It only affects a View with an ID of 375, adjust acordingly if needed.
  • It only affects Views with actual results: if the View matches no result, the same “No items found” or whatever you have between the wpv-no-items-found shortcode applies.
  • It returns only what is between the HTML comments <!– wpv-loop-start –> and <!– wpv-loop-end –> , excluding them. Only content between those HTML comments is returned, as is.

Notice that, with this applied to a given View ID:

  • Pagination, specially AJAX pagination, will not work.
  • Parametric search, specially AJAXed parametric search, will not work.
  • Other future features will not work either.

So this is to be used if and only if you know what you are doing and you are going to use the View output as source for anything else.

But also notice that this only clears the View structure.

Building as example JSON inside a View output is wrong because we can not address quoting problems.

Please use this with caution, explaining the side effects and rsponsibly.

Evaluate for recurring Date

This creates a ShortCode to use when Date CF (Timestamps) need to be evaluated by recurring dates, just as for Birthdays.

Create a CPT, associate a Date CF to it, list CPT in a View and see in the code how to evaluate.
Remember to Register the ShortCode in Views Settings.

function born_today_func( $atts ) {
    extract(shortcode_atts(array(
        'birthday' => get_post_meta(get_the_ID(), 'wpcf-your_slug', true),
 
    ), $atts)
           );
 
    if(((date('d', $birthday)) == date('d')) && (date('m', $birthday)) == date('m')){
        return 1;
    }else{
        return 0;
    }
}
add_shortcode( 'born-today', 'born_today_func' );

Evaluate like this in your view loop: