Notice: Undefined variable: string in /home/u665484253/domains/wpcodekit.com/public_html/wp-content/themes/twentytwenty-child/functions.php on line 61
How to use WP_Query with have_posts()?
global $wp_query;
$original_query = $wp_query;
$wp_query = null;
$wp_query = new WP_Query( $args );
if ( have_posts() ) :
while ( have_posts() ) : the_post();
the_title();
the_excerpt();
endwhile;
else:
echo ‘no posts found’;
endif;
$wp_query = null;
$wp_query = $original_query;
wp_reset_postdata();
Get more information
Read More Posts
- How to update data in database in wordpress?
- How to fetch file name, extension and basename from url in php?
- How to use inner html value or data in php from javascript(innerHTML)?
- How to count number of days in between two dates in php?
- How to fetch data (messages) in every second with ajax (setinterval) from mysql (PHP) in wordpress?