Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.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 获取所有帖子的标题_Php_Wordpress - Fatal编程技术网

Php 获取所有帖子的标题

Php 获取所有帖子的标题,php,wordpress,Php,Wordpress,我使用Wordpress,我还通过XMLRPC基于定期添加到的RSS提要创建帖子 我想要的是阅读所有的帖子标题,将它们与RSS提要进行比较,然后只在没有帖子标题的地方发布到Wordpress 我正在尝试以下代码: <?php define('WP_USE_THEMES', false); require('../wp-load.php'); query_posts('showposts=-1&author=1&post_status=publish'); ?> &l

我使用Wordpress,我还通过XMLRPC基于定期添加到的RSS提要创建帖子

我想要的是阅读所有的帖子标题,将它们与RSS提要进行比较,然后只在没有帖子标题的地方发布到Wordpress

我正在尝试以下代码:

<?php
define('WP_USE_THEMES', false);
require('../wp-load.php');
query_posts('showposts=-1&author=1&post_status=publish');
?>

<?php while (have_posts()): the_post(); ?>

<?php the_title(); ?>

<?php endwhile; ?>

这将从
发布的
帖子中获取所有标题,然后我需要执行相同的操作来获取
草稿
帖子


我需要将这些标题写入一个数组?

编写自己的查询来检索文章标题将比使用
query\u posts
更有效。像这样的方法应该会奏效:

$titles = $wpdb->get_col(
    "SELECT post_title
    FROM $wpdb->posts
    WHERE post_type = 'post'
    AND post_author = 1 
    AND post_status IN ('publish', 'draft')"
);

那么问题是什么?你被困在哪里的代码?更新了获取_title()的问题;对任何人都是如此。。不确定它是否依赖于版本,但我最终编写并使用了这个:
global$wpdb$结果=$wpdb->get_results(“从wp_posts中选择post_name、id、post_type,其中post_键入('post','page')和post_状态('publish','draft'),按post_name ASC排序”);打印(结果)很少有需要直接查询数据库的实例,这不是其中之一。