$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>wp query template tags not working|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wp query template tags not working

matteradmin9PV0评论

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.

Share Improve this question edited Jan 13, 2019 at 13:35 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Jan 13, 2019 at 12:59 alpha.romeoalpha.romeo 491 gold badge1 silver badge5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far