Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6711539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:09:09+00:00 2026-05-26T08:09:09+00:00

Apologies if this is a simple one, I’m getting my head round how data

  • 0

Apologies if this is a simple one, I’m getting my head round how data objects work in Silverstripe.

My task is to obtain a list of posts from a wordpress blog (currently on /blog) on our site, and display the most recent post in the footer, and in another case, display posts by certain editors on their page.

I’ve seen the manual page for SqlQuery, but whenever I try anything from it I get an error. The code I’m using is based on the example, and looks like this:

    $sqlQuery = new SQLQuery();
    $sqlQuery->select = array(
      'post_title',
      'post_content',
      'post_name'
    );
    $sqlQuery->from = array("
      wp_posts
    ");
    $sqlQuery->where =  array("
        post_status = 'publish'
    ");
    $sqlQuery->orderby = "
        post_date DESC
    ";
    // $sqlQuery->groupby = "";
    // $sqlQuery->having = "";
    // $sqlQuery->limit = "";
    // $sqlQuery->distinct = true;

    // get the raw SQL
    $rawSQL = $sqlQuery->sql();

    // execute and return a Query-object
    $result = $sqlQuery->execute();
    $myDataObjectSet = singleton('wp_posts')->buildDataObjectSet($result);
    var_dump($myDataObjectSet->First()); // DataObject

The error I’m getting is:

[User Error] Bad class to singleton() – wp_posts

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:09:09+00:00Added an answer on May 26, 2026 at 8:09 am

    This will return you a DataObjectSet of your WordPress posts (latest 3 in this case). Assuming WordPress resides in the same database as SilverStripe.

    function LatestPosts() {
        $sqlQuery = new SQLQuery();
        $sqlQuery->select("post_title", "post_content");
        $sqlQuery->from("wp_posts");
        $sqlQuery->where("post_status = 'publish'");
        $sqlQuery->orderby("post_date DESC");
        $sqlQuery->limit(3);
    
        if ($result = $sqlQuery->execute()) {
            $wp_posts = new DataObjectSet();
            foreach($result as $row) {
                $wp_posts->push(new ArrayData($row));
            }
            return $wp_posts;
        }
    
        return;
    }
    

    You can then iterate over your DataObjectSet in your template.

    <% if LatestPosts %>
        <% control LatestPosts %>
            <h3>$post_title</h3>
            <div>$post_content</div>
        <% end_control %>
    <% end_if %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably a simple one but I cant get my head around it.
Apologies in advance. This seems like a simple task, but hours later on Google
Apologies if this question is a bit obscure, I've been banging my head against
Apologies if this is a simple question but googling hasn't been able to help
This might be a simple one for you guys, im learning Javascript and have
Apologies if this is a stupid/easy question, but still getting used to everything in
This is a bit of an odd one and apologies if I don't explain
This is a simple one, and one that I thought would have been answered.
have Googled the cr*p out of this one so apologies if the answer is
I'm new to SSRS, so I apologize if this question is too simple: I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.