WordPress.org

Forums

Get latest posts with relativ author, tags and categories with only 1 request (3 posts)

  1. StErMi
    Member
    Posted 4 years ago #

    Hello everyone. I'm developing an application that read data from my WordPress.

    At the moment I'm using directly WordPress functions: http://codex.wordpress.org/Function_Reference/

    I'll make an example. I want to load latest 15 posts with their relative author information, tags and categories.

    So I have to call

    get_posts that gives me informations about latest 15 posts and than for each of them I have to call get_userdata for author information, get_the_tags for tags and the function to get categories.

    So in total I have 1 query to get 15 posts and 45(15x3) queries to get informations about posts.

    Is there a way to create my own function that gives me with 1 query FULL informations about latest posts?

  2. StErMi
    Member
    Posted 4 years ago #

    This is the query I need:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    As you can see I'm pretty new to WordPress. Now With this query I get a record for each tag and category of each post.
    I was wondering if WordPress has some internal function to manipulate this data and get something organized like a Post object with an array of categories and tags. Then I will encode in JSON or XML.

    Can you help me?

  3. StErMi
    Member
    Posted 4 years ago #

    Uhm at the moment I cannot modify my previous post.

    This is the code I was talking about: http://pastebin.com/thYiryr4

    Also, is there a better way to do that? I mean to load latest posts with author, tags and categories with only 1 query?

Topic Closed

This topic has been closed to new replies.

About this Topic