Php 为什么是have_posts():_post()不工作

Php 为什么是have_posts():_post()不工作,php,wordpress,Php,Wordpress,我正试图用我的插件显示所有post in表。我已经有三篇文章,但下面的代码没有显示任何内容 插件页面代码: <?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?> <tr> <td id="username"><?php the_title(); ?></td>

我正试图用我的插件显示所有post in表。我已经有三篇文章,但下面的代码没有显示任何内容

插件页面代码:

<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
               <tr>
                  <td id="username"><?php the_title(); ?></td>

                  <td>
                      <video class="video" width="200" height="100">
                        <source src="<?php echo $rs->user->profile_video;?>" type="video/mp4">
                        Your browser does not support the video.
                      </video>
                </td>
                  <td id="status"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"></a></td>
                  <td><select class="action">
                      <option>-Select-</option>
                      <option value="1" >Active</option>
                      <option value="0">Inactive</option>
                      <option value="edit">Edit</option>
                      <option value="4">Delete</option>
                    </select></td>
                </tr>


<?php endwhile; ?>
<?php endif; ?>


您可以使用WP_查询来检索您的帖子。WP_Query是一个类,其构造函数将返回一个对象,该对象也具有循环函数

注意
$wq
变量和
$wq->have_posts()

重要提示:对于在循环内调用的函数(
title()
content()
permalink()
,等等),不要在
$wq
变量前加前缀。它们的工作方式与使用
query\u posts()



我也有同样的问题

当我使用print_r($wq); 我得到了一个结果,但是_posts()返回了false

我使用以下代码为我修复了它:

<?php
$args = array(
      'posts_per_page'   => -1,
      'offset'           => 0,
      'orderby'          => 'date',
      'order'            => 'ASC',
      'post_type'        => 'post',

    );
$myposts = get_posts( $args );

   foreach ( $myposts as $post ) : setup_postdata( $post );
?>

<p>my html</p>

<?php endforeach; wp_reset_postdata(); ?>

我的html


在循环之前是否运行了wp\u查询或查询发布?否。我认为这对have_post()没有影响;谢谢<代码>查询_posts()。为什么@rnevius
WP\u Query()
get\u posts()
不起作用我认为这应该得到+1,因为使用Linux:PNot不再起作用。。这是使用
query\u posts()
onlyNOT working:
$wq=new WP\u query($args=null);?>工作:
query_posts($arg=null);?>
<?php
$args = array(
      'posts_per_page'   => -1,
      'offset'           => 0,
      'orderby'          => 'date',
      'order'            => 'ASC',
      'post_type'        => 'post',

    );
$myposts = get_posts( $args );

   foreach ( $myposts as $post ) : setup_postdata( $post );
?>

<p>my html</p>

<?php endforeach; wp_reset_postdata(); ?>