Get the Title of all posts

Im using WordPress, Im also creating posts via XMLRPC based on an RSS feed that is added to periodically.

What I want is to read all post titles, compare those against the RSS feed, then only post to WordPress where the post titles dont exist.

Read More

I’m trying this code:

<?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; ?>

This gets all titles from published posts, I then need to do the same to get the draft posts.

I need to write these title’s to an array?

Related posts

Leave a Reply

1 comment

  1. It will be more efficient to write your own query to retrieve just the post titles rather than using query_posts. Something like this should work:

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