Skip to content

Instantly share code, notes, and snippets.

@conquistadorjd
Last active February 16, 2019 14:17
Show Gist options
  • Save conquistadorjd/3794d12562148cbd70aa6b719aaffd8b to your computer and use it in GitHub Desktop.
Save conquistadorjd/3794d12562148cbd70aa6b719aaffd8b to your computer and use it in GitHub Desktop.
WordPress
WordPress Tricks and Hacks
<?php
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
/* Restore original Post Data */
wp_reset_postdata();
} else {
echo '<p>Sorry, no related articles to display.</p>'
// no posts found
}
?>
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
/* Restore original Post Data */
wp_reset_postdata();
} else {
// no posts found
}
<?php
// the query
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<!-- pagination here -->
<!-- the loop -->
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php endwhile; ?>
<!-- end of the loop -->
<!-- pagination here -->
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
<?php
// Creating array
$args = array(
'posts_per_page' => 15,
'orderby' => 'date',
'order' ='ASC'
);
// Initiate the custom query
$custom_query = new WP_Query( $args );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment