Ready to get started?Download WordPress


error adding my query column in array (2 posts)

  1. mark2k
    Posted 1 year ago #

    I have my code as below:

     * Template Name: api
    header('Cache-Control: no-cache, must-revalidate');
    header('Content-type: application/json');
    $query = $wpdb->get_results(
    	"SELECT <code>ID</code>,<code>post_title</code>,<code>post_content</code>,<code>post_date</code> ,<code>post_status</code>
    	FROM $wpdb->posts WHERE <code>post_type</code> = 'post' AND post_status='publish'
     $response["megaposts"] = array();
     $shyerpost = array();
    foreach ( $query as $inpost )
         $shyerpost["pid"] = $inpost->ID;
         $shyerpost["post_title"] = $inpost->post_title;
         $shyerpost["post_content"] = $inpost->post_content
         $shyerpost["post_date"] = $inpost->post_date;
    	 array_push($response["megaposts"], $shyerpost);
    echo json_encode($response);

    Anytime i run this page I get this error:

    Parse error: syntax error, unexpected '$shyerpost' (T_VARIABLE) in C:\wamp\www\pccchurch\wp-content\themes\Mark2kBusiness\postapi.php on line 26

    Please help

  2. vtxyzzy
    Posted 1 year ago #

    You are missing a semicolon at the end of line 25:

    $shyerpost["post_content"] = $inpost->post_content

Topic Closed

This topic has been closed to new replies.

About this Topic