I have a shortcode where I'm trying to get a specific string from the $args
array below.
Query:
$args = array( //'post_type' => $posttype, 'post_type' => explode( ', ', $posttype ), ); $myquery = new WP_Query( $args );
Conditional:
if ( $posttype == 'cpt_press' ) : the_content(); else : the_excerpt(); endif;
Shortcode:
[myquery posttype='cpt_press']
In the conditional above, I'm able to retrieve all posts with post type 'cpt_press'
if I don't use explode. The reason I used explode is so I could do this:
[myquery posttype='cpt_press, cpt_two, cpt_three, cpt_etc']
Any help?
UPDATED CODE BLOCK
function myshortcode( $params, $content = null ) { global $post; extract( shortcode_atts( array( 'posttype' => '', 'meta_key' => '', 'priority' => '', 'meta_compare' => '', 'layout' => 'rows', 'cols' => 1, 'tag' => '', 'count' => 10, 'orderby' => 'date', 'order' => 'DESC' ), $params ) ); $args = array( 'post_type' => explode( ',', $posttype ), ); $myquery = new WP_Query( $args ); ob_start(); ?><div class="row"><?php // The Loop if ( $myquery->have_posts() ) : while( $myquery->have_posts() ) : $myquery->the_post(); if ( $posttype == 'cpt_press' ) : the_content(); else : the_excerpt(); endif; endwhile; endif; wp_reset_postdata(); ?></div><?php return ob_get_clean(); } add_shortcode( 'myquery', 'myshortcode' );
if ( in_array( 'cpt_press', $posttype ) )
.var_dump
the "$posttype" and make sure it is an array with "cpt_press" in it?