Question : wordpress custom php use wp query
Answered by : matteo-puppis
if ( ! defined('ABSPATH') ) { /** Set up WordPress environment */ require_once( dirname( __FILE__ ) . '/wp-load.php' );
}
global $wpdb;
$results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}options WHERE option_id = 1", OBJECT );
Source : https://wordpress.stackexchange.com/questions/258694/include-wp-query-in-my-own-php-file | Last Update : Wed, 08 Jul 20
Question : Wordpress WP Query
Answered by : shubham-twvfvblalfuc
<?php $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); ?> <h2><?php echo get_the_title(); ?></h2> <?php endwhile; wp_reset_postdata(); ?>
Source : | Last Update : Sun, 07 May 23
Question : wp query
Answered by : homeless-hornet-bu52khzmzyd2
<?php
$display_posts = -1; // dispay all posts
$args = array( 'post_type' => 'post', 'posts_per_page' => $display_posts, // 'orderby' => 'date', // 'order' => 'DESC', 'post_status' => 'publish',
);
$QUERY = new WP_Query($args);
if($QUERY->have_posts()): while ($QUERY->have_posts()): $QUERY->the_post(); echo "<h2>".get_the_title()."</h2>"; endwhile; wp_reset_query();
endif;
?>
Source : | Last Update : Mon, 08 May 23
Question : use wordpress $query = new WP_Query()
Answered by : realdee
<?php
// 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>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
Source : https://developer.wordpress.org/reference/classes/wp_query/ | Last Update : Fri, 05 Aug 22