mysql - How can I combine this php statement to get the results of multiple variable inputs? -
this wordpress query not wordpress related question. shows posts have meta_key extra1 , meta_value test
<?php $customkey1 = extra1; ?> <?php $customvalue1 = test; ?> <?php query_posts('meta_key=' . $customkey1 . '&meta_value=' . $customvalue1 . ''); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php the_title(); ?> <?php endwhile; ?> <?php endif; ?>
my question how can still show posts have extra1
metakey , test
metavalue posts have extra2
metakey , test2
metavalue in same query. combination of 2 or more variables.
so want combine results of 2 queries? check out may need make 2 query objects , combine them.
something (note, not have wordpress installed, nor use wordpress. assuming api not lie):
<?php // query $the_query = new wp_query( $args ); $the_second_query = new wp_query( $args ); // loop while ( $the_query->have_posts() ) : $the_query->the_post(); echo '<li>'; the_title(); echo '</li>'; endwhile; // second loop while ( $the_second_query->have_posts() ) : $the_second_query->the_post(); echo '<li>'; the_title(); echo '</li>'; endwhile; // reset post data wp_reset_postdata(); ?>
note: hideous, ugly, , work in cases should considered wrong professionals. more elegantly, @ least use function parse post. elegantly, has been suggested elsewhere, encapsulate combined query in mysql bit. given op's knowledge, seems "best approach" solving problem, once. (repeated application of approach turn messy nightmare)
Comments
Post a Comment