I create a page : contact-us then I specify a template for this page and this is the template code:
<?php
/*
Template Name: Template wp_query
*/
?>
<?php
$arg = array (
'post_type' => 'post',
'post_per_page' => -1 ,
);
$test = new WP_Query($arg);
var_dump($test);
if ($test->have_posts()) {
while ($test-> have_posts()) : $test-> the_post();
echo $test->get_the_title();
echo $test->get_the_content;
endwhile;
}
wp_reset_query();
?>
the result page is blanck even if the var_dump($test) return the list of post with the information. for your information i tried query_post() and it works fine. please help me.
I create a page : contact-us then I specify a template for this page and this is the template code:
<?php
/*
Template Name: Template wp_query
*/
?>
<?php
$arg = array (
'post_type' => 'post',
'post_per_page' => -1 ,
);
$test = new WP_Query($arg);
var_dump($test);
if ($test->have_posts()) {
while ($test-> have_posts()) : $test-> the_post();
echo $test->get_the_title();
echo $test->get_the_content;
endwhile;
}
wp_reset_query();
?>
the result page is blanck even if the var_dump($test) return the list of post with the information. for your information i tried query_post() and it works fine. please help me.
Template tags are not methods of WP_Query
object. They are functions.
On the other hand have_posts
and the_post
are methods of WP_Query
.
So in your code you should use:
while ($test->have_posts()) : $test->the_post();
as you do, but then:
echo get_the_title();
echo get_the_content();
Also... if you want to echo these values, it would be much better to use the_title
and the_content
instead - there are some additional filters and actions fired up.