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 8499163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:35:42+00:00 2026-06-11T00:35:42+00:00

I want to get the data from WordPress DB, pushed them into array and

  • 0

I want to get the data from WordPress DB, pushed them into array and past the data to JS.

Got it all working except pushing the data into array in foreach ($posts as $post).

Full method:

        $array = array(); 
        $category_name = "locations";
        $args = array(
            'numberposts' => -1,
            'category_name' => $category_name
        );

        $posts = get_posts($args);      
        foreach ($posts as $post){
            array_push( $array, array(

                "title" => the_title($post->ID),
                "cnt" => the_content($post->ID),
                "id" => the_ID($post->ID),
                "link" => the_permalink($post->ID)

            )); 
        }

When I do print_r($array) i get a following mix:

Post 39http://localhost:8080/testing/post-3/Post 27http://localhost:8080/testing/post-2/Post 15http://localhost:8080/testing/post-1/Array
(
    [0] => Array
        (
            [title] => 
            [cnt] => 
            [id] => 
            [link] => 
        )

    [1] => Array
        (
            [title] => 
            [cnt] => 
            [id] => 
            [link] => 
        )

    [2] => Array
        (
            [title] => 
            [cnt] => 
            [id] => 
            [link] => 
        )

)

What is going on? Why is the data not placed correctly into the array?
Any suggestions much appreciated.

  • 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-06-11T00:35:44+00:00Added an answer on June 11, 2026 at 12:35 am

    Those template tags need to have their echo variable set to false to work in that context. They also don’t take post ID as a variable, they assume the current post if postdata is setup. Try:

    the_title('','',false)
    

    https://codex.wordpress.org/Function_Reference/the_title


    -~ -~ -~ -~ -~ -~ -~ -~ CLARIFICATION EDIT -~ -~ -~ -~ -~ -~ -~ -~

    The tidiest solution to this problem was actually to directly address the wp $post object. So for the title string $post->post_title and for the content $post->post_content

    The fields available in the $post object are listed here:

    http://codex.wordpress.org/Function_Reference/get_post#Return

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get data from my Sqlite database and put it into this
I want to get data from a DMA enabled, PCIe hardware device into user-space
I want to get individual posts from a blogger blog, and make them into
i want to get data from rules into a list in order to be
I want to get data from mysql database with the help of DataImportHandler so
I want to get data from table in MySQL and to show it in
I want to get data from two tables. I have patient first name and
I want to get data from a table in my MySQL database. $linkID =
I want to get data from two tables with single Entity class. How?? public
Whenever I want to get data from a plist file I use the following

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.