Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何列出所有word press页面及其URL,按草稿和已发布筛选?_Php_Wordpress - Fatal编程技术网

Php 如何列出所有word press页面及其URL,按草稿和已发布筛选?

Php 如何列出所有word press页面及其URL,按草稿和已发布筛选?,php,wordpress,Php,Wordpress,我需要在我们的WordPress页面上创建一个报告。报告应包括页面标题及其链接到实际页面的URL。但是,我们不想列出所有页面。我们需要根据草稿或已发布的文档对其进行筛选 是否可以列出按草稿筛选或发布的页面?(作者并不重要) 是的,您必须使用并传递参数来显示已发布或起草的页面: <?php $args = array( 'post_type' => 'page', 'post_status' => array( 'publish', 'draft' ) );

我需要在我们的WordPress页面上创建一个报告。报告应包括页面标题及其链接到实际页面的URL。但是,我们不想列出所有页面。我们需要根据草稿或已发布的文档对其进行筛选

是否可以列出按草稿筛选或发布的页面?(作者并不重要)


是的,您必须使用并传递参数来显示已发布或起草的页面:

<?php 
$args = array(
    'post_type' => 'page',
    'post_status' => array( 'publish', 'draft' )
);

// the query
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
    <!-- the loop -->
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
        <h2><?php the_title(); ?></h2>
    <?php endwhile; ?>
    <!-- end of the loop -->
    <?php wp_reset_postdata(); ?>

<?php else : ?>
    <p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

这里的关键是使用
post\u status
来过滤帖子。

是的,您必须使用并传递参数来显示发布或起草的页面:

<?php 
$args = array(
    'post_type' => 'page',
    'post_status' => array( 'publish', 'draft' )
);

// the query
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
    <!-- the loop -->
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
        <h2><?php the_title(); ?></h2>
    <?php endwhile; ?>
    <!-- end of the loop -->
    <?php wp_reset_postdata(); ?>

<?php else : ?>
    <p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>


这里的关键是使用
post\u status
来过滤帖子。

有两种方法,一种是使用
get\u posts
,另一种是使用
WP\u Query

Argumnet对于两种方式都是相同的

    $args=array(  
         'posts_per_page' => -1,
         'post_type' => 'page',
         'post_status' => array( 'publish', 'draft' )
    );
方法-1-获取帖子()

    $pageslist = get_posts( $args ); 
    foreach($pageslist as $key=>$val)
    {
        $pageid=$val->ID;
        $link= get_permalink($pageid);
        $title=$val->post_title;
        echo "Page title: {$title}<br>Page id: {$pageid}<br> Link:{$link}<br><br>";
    }
$pageslist=get_posts($args);
foreach($pageslist作为$key=>$val)
{
$pageid=$val->ID;
$link=get_permalink($pageid);
$title=$val->post_title;
echo“页面标题:{$title}
页面id:{$pageid}
链接:{$Link}

”; }
方法-2-可湿性粉剂查询

    $page_data = new WP_Query( $args ); 
    if ( $page_data->have_posts() ) :

        while ( $page_data->have_posts() ) : $page_data->the_post();
        ?>
                <p> Page Title:
          <?php   the_title();?></p>
               <p> Page ID:
          <?php the_ID();?></p>
                <p> Page link:
          <?php the_permalink();?></p>
                <br><br>
                <?php 
         endwhile;
            wp_reset_postdata();
       else :  esc_html_e( 'Sorry, no posts matched your criteria.' ); 
    endif;
$page\u data=新的WP\u查询($args);
如果($page\u data->have\u posts()):
而($page_data->have_posts()):$page_data->the_post();
?>
页面标题:

页面ID:

页面链接:




有两种方法,一种是使用
get\u posts
,另一种是使用
WP\u Query

Argumnet对于两种方式都是相同的

    $args=array(  
         'posts_per_page' => -1,
         'post_type' => 'page',
         'post_status' => array( 'publish', 'draft' )
    );
方法-1-获取帖子()

    $pageslist = get_posts( $args ); 
    foreach($pageslist as $key=>$val)
    {
        $pageid=$val->ID;
        $link= get_permalink($pageid);
        $title=$val->post_title;
        echo "Page title: {$title}<br>Page id: {$pageid}<br> Link:{$link}<br><br>";
    }
$pageslist=get_posts($args);
foreach($pageslist作为$key=>$val)
{
$pageid=$val->ID;
$link=get_permalink($pageid);
$title=$val->post_title;
echo“页面标题:{$title}
页面id:{$pageid}
链接:{$Link}

”; }
方法-2-可湿性粉剂查询

    $page_data = new WP_Query( $args ); 
    if ( $page_data->have_posts() ) :

        while ( $page_data->have_posts() ) : $page_data->the_post();
        ?>
                <p> Page Title:
          <?php   the_title();?></p>
               <p> Page ID:
          <?php the_ID();?></p>
                <p> Page link:
          <?php the_permalink();?></p>
                <br><br>
                <?php 
         endwhile;
            wp_reset_postdata();
       else :  esc_html_e( 'Sorry, no posts matched your criteria.' ); 
    endif;
$page\u data=新的WP\u查询($args);
如果($page\u data->have\u posts()):
而($page_data->have_posts()):$page_data->the_post();
?>
页面标题:

页面ID:

页面链接:




嗯,只列出了两个标题。没有linkshmm,只列出了两个标题。没有链接第一个没用。第二个列出了标题、id和链接。我只需要标题(作为链接)。thanx,我看看我是否可以编辑它并使其工作是的,我通过改变行也使第二个工作得很好:第一个不工作。第二个列出了标题、id和链接。我只需要标题(作为链接)。thanx,我看看我是否可以编辑它并使其工作是的,我通过改变行也得到了第二个工作正常: