Skip to content

Instantly share code, notes, and snippets.

/page-topic Secret

Created July 6, 2016 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/944264e6cb6f10ea4948ef4240cf2b60 to your computer and use it in GitHub Desktop.
Save anonymous/944264e6cb6f10ea4948ef4240cf2b60 to your computer and use it in GitHub Desktop.
Multiple/nested query in a single loop
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-content">
<div class="scripts-order">
<?php $link = $_SERVER['REQUEST_URI'];
if (substr_count($link, '?') == 0) {
$link .= '?'; }
if(isset($_GET["ord"]) && trim($_GET["ord"]) == 'DESC'){
echo "<a href='". esc_url( remove_query_arg( 'ord' ) )."' title='Ascending'><i class='fa fa-angle-up'></i></a>"; }
else {
echo "<a href='".$link."&ord=DESC' title='Descending'><i class='fa fa-angle-down'></i></a>";
}
?>
</div>
<?php
$custom_args = array(
'post_type' => 'scripts',
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => -1
);
if(isset($_GET["ord"]) && trim($_GET["ord"]) == 'DESC'){
$custom_args[order] = 'DESC'; } else { $custom_args[order] = 'ASC';
}
$custom_query = new WP_Query( $custom_args ); ?>
<div class="topic-list">
<?php
if ( $custom_query->have_posts() ) :
while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
<div class="row">
<div class="col-md-1">
<?php $field_name = "video_number";
$field = get_field_object($field_name);
if( get_field('video_number') ):
echo $field['value'];
endif; ?>
</div>
<div class="col-md-9">
<?php
$field_name = "topic";
$field = get_field_object($field_name);
if( get_field('topic') ):
echo $field['value'];
endif; ?>
</div>
<div class="col-md-1">
<?php
the_field('timestamp');
?>
</div>
<div class="col-md-1" id="topic-chosen">
<?php $field = get_field('chosen');
if ($field == 'Yes') {
echo "<i class='fa fa-check'></i>";
} else {
echo "<i class='fa fa-close'></i>";
}
?>
</div>
</div><!-- .row -->
<?php endwhile;
endif;
wp_reset_postdata(); ?>
</div><!-- end topic-list -->
<?php the_content(); ?>
</div><!-- .entry-content -->
</article><!-- #post-## -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment