Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
function demo_shortcode(){
$args = array(
'post_type' => 'product',
'meta_query'=> array(
'relation' => 'OR',
array(
'key' => 'some_key',
'value' => '42',
'compare' => 'IN',
),
array(
'key' => 'some_key',
'compare' => 'NOT EXISTS',
),
),
);
$new_posts = WP_Query( $args );
// the loop
if ( $new_posts->have_posts() ) : while ( $new_posts->have_posts() ) : $new_posts->the_post(); ?>
<!-- post content goes here -->
<?php the_title(); ?>
<?php endwhile; else: ?>
<h3>Oops!! Looks like something went wrong. Please get in touch with the site <a href="mailto:<?php echo get_bloginfo('admin_email'); ?>">administrator</a> and we'll get this sorted out</h3>
<?php endif; ?>
<?php wp_reset_postdata();
}
add_shortcode( 'demo_code', 'demo_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment