-1

I need all the post ids with the corresponding title and post date.

Currently getting only ids

 $posts_array = get_posts( 'posts_per_page=999999999999&fields=ids' );

need

[{
"id" : 9,
"post_date" : "2014-06-11 07:04:55",
"post_title" : "title.."
}, 
    {..}, 
    {..},..
]

Scenario:

  1. Post will be used to show in tablet/Mobile (with infinite scroll).
  2. Call web service to get Posts.
  3. the post must return result in a paging manner like 1-20, 20-40 (from all posts) for subsequent calls.

  4. Don't want to load all the posts as it will arise performance issue.

closed as off-topic by Pieter Goosen, Nicolai, kaiser Jul 22 '14 at 9:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    Have you tried anything yourself? Have you checked the WordPress Codex? This seems like a "read the manual"-question. – engelen Jun 11 '14 at 8:07
  • You have fields=ids, so what did you expect? :) – kaiser Jul 22 '14 at 9:03
  • need id, tiles and post date, is there any shortcut way not using recursive call ie; again requesting title+post date from ids – Tusar Jul 22 '14 at 11:01
1

You can use get_posts to get a list of posts, and then the WP_Post member variables to get and display the data that you need

You van do something like this. You can refine it as you need

<?php
$args = array( 'posts_per_page' => -1); 
$posts= get_posts( $args );
if ($posts) {
    foreach ( $posts as $post ) {
        setup_postdata($post);
        echo '<p>' . $post->post_title . '(' . $post->ID . ')'  . ' was posted on  ' .  $post->post_date . '</p>';
    }
}

This will output

TEST POST SUB(312) was posted on 2014-05-29 15:47:26

  • Did you manage to solve your problem? Was my answer useful in solving your problem. If yes, please accept my answer. If your problem is not solved, where is my code lacking. If you solved your own problem it would be nice if you post that as an answer to your question – Pieter Goosen Jun 19 '14 at 18:07
  • Hi @Pieter. Your post is good for front end, but I'm using web Service and the response must be in JSON. I need that is a single line query(if possible). I want that also in paging style ie: from post 1-20, 20-40 (from all posts). – Tusar Jul 18 '14 at 5:53
  • Please update your question as your question is misleading – Pieter Goosen Jul 18 '14 at 5:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.