figure out how to merge array for filter loop

2019-08-21 13:28发布

I am creating a Wordpress website that shows events through the Eventbrite API. Using the API from https://github.com/Automattic/eventbrite-api

I was able to get the data. create a template with the events data and create a slider too. What I am trying to do is filter these events by venue id and organizer id.

What I have done so far.

Created a loop that goes through the events and inputs the for each loop. But it comes out as each city is a separate array so a separate drop down for each city.

<div id="venues" class="form-group my-5">

    <form 
        id="venue-select" 
        class="venue-select input-group-prepend ml-auto mt-5" 
        action="<?php echo esc_url(home_url('/')); ?>" 
        method="get"
    >

        <?php printf(eventbrite_event_venue()); ?>

        <?php

        // Set up and call our Eventbrite query.
        $venue_filter = new Eventbrite_Query(apply_filters( 'eventbrite_query_args', array(
            'display_private' => true, // boolean)
            'status' => 'live',         // string (only available for display_private true)
            'limit' => 100,            // integer
        )));

        if ($venue_filter->have_posts()) :

            while ($venue_filter->have_posts()) : $venue_filter->the_post();

                $result =  array(eventbrite_event_venue());

                echo print_r($result);

                $venues =   array_merge($result);

                $venues_array = array('Choose A City');

                $get_venues = $venues;

                foreach ( $get_venues as $venue ) {
                    $venues_array[] .= $venue;
                }

                $venue_id = array_unique($venues_array);

                printf('<select name="%s" class="postform form-control">', esc_attr($venue));

                foreach($get_venues as $venue) {
                    printf( '<option value="%s">%s</option>', esc_attr( $venue), esc_html(eventbrite_event_venue()->address->city ) );
                }

                print('</select>');


            endwhile;  

        endif;

        wp_reset_postdata();
        wp_reset_query(); 

        ?>

        </select>
    </form>
</div>

The following code

              $result =  array(eventbrite_event_venue());
               echo print_r($result);

outputs the following:

Array
 (
   [0] =&gt; stdClass Object
    (
        [address] =&gt; stdClass Object
            (
                [address_1] =&gt; 350 5th Avenue,
                [address_2] =&gt; 5th Floor, The LAB
                [city] =&gt; New York
                [region] =&gt; NY
                [postal_code] =&gt; 10118
                [country] =&gt; US
                [latitude] =&gt; 40.7353956
                [longitude] =&gt; -73.99462499999998
                [localized_address_display] =&gt; 350 5th Avenue, 5th 
                Floor, The LAB, New York, NY 10118
                [localized_area_display] =&gt; New York, NY
                [localized_multi_line_address_display] =&gt; Array
                    (
                        [0] =&gt; 350 5th Avenue
                        [1] =&gt; 5th Floor, The LAB
                        [2] =&gt; New York, NY 10118
                    )

            )

        [resource_uri] =&gt; 
        https://www.eventbriteapi.com/v3/venues/25816848/
        [id] =&gt; 25816848
        [age_restriction] =&gt; 
        [capacity] =&gt; 
        [name] =&gt; Global Brands Group
        [latitude] =&gt; 40.7353956
        [longitude] =&gt; -73.99462499999998
    )

   )
   1Array
   (
[0] =&gt; stdClass Object
    (
        [address] =&gt; stdClass Object
            (
                [address_1] =&gt; 350 5th Avenue,
                [address_2] =&gt; 5th Floor, HR Training Room
                [city] =&gt; New York
                [region] =&gt; NY
                [postal_code] =&gt; 10118
                [country] =&gt; US
                [latitude] =&gt; 40.7484799
                [longitude] =&gt; -73.98542450000002
                [localized_address_display] =&gt; 350 5th Avenue, 5th Floor, HR Training Room, New York, NY 10118
                [localized_area_display] =&gt; New York, NY
                [localized_multi_line_address_display] =&gt; Array
                    (
                        [0] =&gt; 350 5th Avenue
                        [1] =&gt; 5th Floor, HR Training Room
                        [2] =&gt; New York, NY 10118
                    )

            )

        [resource_uri] =&gt; https://www.eventbriteapi.com/v3/venues/25536431/
        [id] =&gt; 25536431
        [age_restriction] =&gt; 
        [capacity] =&gt; 
        [name] =&gt; Global Brands Group
        [latitude] =&gt; 40.7484799
        [longitude] =&gt; -73.98542450000002
    )

   )
   1Array
    (
[0] =&gt; stdClass Object
    (
        [address] =&gt; stdClass Object
            (
                [address_1] =&gt; 350 5th Avenue,
                [address_2] =&gt; 5th Floor, HR Training Room
                [city] =&gt; New York
                [region] =&gt; NY
                [postal_code] =&gt; 10118
                [country] =&gt; US
                [latitude] =&gt; 40.7484799
                [longitude] =&gt; -73.98542450000002
                [localized_address_display] =&gt; 350 5th Avenue, 5th Floor, HR Training Room, New York, NY 10118
                [localized_area_display] =&gt; New York, NY
                [localized_multi_line_address_display] =&gt; Array
                    (
                        [0] =&gt; 350 5th Avenue
                        [1] =&gt; 5th Floor, HR Training Room
                        [2] =&gt; New York, NY 10118
                    )

            )

        [resource_uri] =&gt; https://www.eventbriteapi.com/v3/venues/25536431/
        [id] =&gt; 25536431
        [age_restriction] =&gt; 
        [capacity] =&gt; 
        [name] =&gt; Global Brands Group
        [latitude] =&gt; 40.7484799
        [longitude] =&gt; -73.98542450000002
    )

   )
    1Array
   (
[0] =&gt; stdClass Object
    (
        [address] =&gt; stdClass Object
            (
                [address_1] =&gt; 350 5th Avenue,
                [address_2] =&gt; 5th Floor, HR Training Room
                [city] =&gt; New York
                [region] =&gt; NY
                [postal_code] =&gt; 10118
                [country] =&gt; US
                [latitude] =&gt; 40.7484799
                [longitude] =&gt; -73.98542450000002
                [localized_address_display] =&gt; 350 5th Avenue, 5th Floor, HR Training Room, New York, NY 10118
                [localized_area_display] =&gt; New York, NY
                [localized_multi_line_address_display] =&gt; Array
                    (
                        [0] =&gt; 350 5th Avenue
                        [1] =&gt; 5th Floor, HR Training Room
                        [2] =&gt; New York, NY 10118
                    )

            )

        [resource_uri] =&gt; https://www.eventbriteapi.com/v3/venues/25536431/
        [id] =&gt; 25536431
        [age_restriction] =&gt; 
        [capacity] =&gt; 
        [name] =&gt; Global Brands Group
        [latitude] =&gt; 40.7484799
        [longitude] =&gt; -73.98542450000002
    )

    )
    1Array
    (
[0] =&gt; stdClass Object
    (
        [address] =&gt; stdClass Object
            (
                [address_1] =&gt; 350 5th Avenue,
                [address_2] =&gt; 5th Floor, HR Training Room
                [city] =&gt; New York
                [region] =&gt; NY
                [postal_code] =&gt; 10118
                [country] =&gt; US
                [latitude] =&gt; 40.7484799
                [longitude] =&gt; -73.98542450000002
                [localized_address_display] =&gt; 350 5th Avenue, 5th Floor, HR Training Room, New York, NY 10118
                [localized_area_display] =&gt; New York, NY
                [localized_multi_line_address_display] =&gt; Array
                    (
                        [0] =&gt; 350 5th Avenue
                        [1] =&gt; 5th Floor, HR Training Room
                        [2] =&gt; New York, NY 10118
                    )

            )

        [resource_uri] =&gt; https://www.eventbriteapi.com/v3/venues/25536431/
        [id] =&gt; 25536431
        [age_restriction] =&gt; 
        [capacity] =&gt; 
        [name] =&gt; Global Brands Group
        [latitude] =&gt; 40.7484799
        [longitude] =&gt; -73.98542450000002
    )

       )

I am not sure how to merge the array into one and when you select the city, the variable should go into here to filter loop for the events

       <?php
        // Set up and call our Eventbrite query.
        $events = new Eventbrite_Query( apply_filters( 
            'eventbrite_query_args', array(
            'display_private' => true, // boolean
            'status' => 'live',         // string (only available for 
             display_private true)
            'nopaging' => true,        // boolean
            'limit' => 100,            // integer
            //'organizer_id' => $organizerfilter,     // integer
            // 'p' => null,                // integer
            // 'post__not_in' => null,     // array of integers
                'venue_id' => $venue,         // integer
            // 'category_id' => null,      // integer
            // 'subcategory_id' => null,   // integer
            // 'format_id' => null,        // integer
        ) ) );
            if ( $events->have_posts() ) :
            while ( $events->have_posts() ) : $events->the_post(); ?>

            <?php get_template_part( 'template-parts/content', 'events' ); ?>

            <?php endwhile;
            // Previous/next post navigation.
            eventbrite_paging_nav();
        else :
            // If no content, include the "No posts found" template.
            get_template_part( 'content', 'none' );
        endif;
        // Return $post to its rightful owner.
        wp_reset_query();
    ?>

0条回答
登录 后发表回答