0

i'm using ticketra as a plugin and i have donig so will untill i want to get all event's tickets by event id, here is the json response of tickets custom post type:

    {
"id": 159,
"date": "2019-01-05T09:49:15",
"date_gmt": "2019-01-05T06:49:15",
"guid": {
"rendered": "http://localhost:8888/cms?post_type=tc_tickets&p=159"
},
"modified": "2019-01-05T12:37:37",
"modified_gmt": "2019-01-05T09:37:37",
"slug": "vip",
"status": "publish",
"type": "tc_tickets",
"link": "http://localhost:8888/cms/tc_tickets/vip",
"title": {
"rendered": "VIP"
},
"content": {
"rendered": "",
"protected": false
},
"parent": 0,
"template": "",
"event_name": [
"121"
],

the event_name value is the event ID

"event_name": [
    "121"

so I made a query as following:

function headlessWP_get_event_tickets($post, $field_name, $request)
{
    $event_name = get_post_meta($post['id'], 'event_name', true);
    $str = $event_name;
    $arrs = explode(",", $str);

    foreach ($arrs as $arr) {
        $args = array(
            'name' => $arr,
            'post_type' => 'tc_events',
            'post_status' => 'publish',
            'numberposts' => -1,
        );
        $ticket = get_posts($args);

        $response[] = array("name" => get_the_title($ticket[0]->ID), "id" => $ticket[0]->ID);
    }
    return $response;

}

but the response comes empty so i did:

$tickets = get_posts(array(
    'posts_per_page' => -1,
    'post_type' => 'tc_tickets',
));

if (!empty($tickets)) {
    foreach ($tickets as $ticket) {
        $event_name[] = get_post_meta($ticket->ID, 'event_name', true);
        $arrs[] = $event_name;
    }
}

foreach ($arrs as $arr) {
    $args = array(
        'name' => $arr,
        'post_type' => 'tc_events',
        'post_status' => 'publish',
        'numberposts' => -1,
    );
    $therapist = get_posts($args);

    $response[] = array("name" => get_the_title($therapist->ID), "id" => $therapist->ID, "slug" => $therapist->post_name, "exerpt" => get_the_excerpt($therapist->ID), "featuredImage" => wp_get_attachment_url(get_post_thumbnail_id($therapist->ID)));
}
return $response;

but also fails any suggestions or help please?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.