• So I’m trying to get terms using…

         $terms = get_terms( array(
            'taxonomy' => 'location',
            'hide_empty' => false,
        ) );

    and use the terms in something like…

    home_url( '/used-cars/location/' . $terms->slug . '/model/' . $anotherterm );

    But I get a WSOD when using get_terms(). What alternative can I use other than get_terms()?

Viewing 2 replies - 1 through 2 (of 2 total)
  • please post your full code

    Thread Starter Nkululeko

    (@oieniuz)

    Hi Michael,

    Basically I want to loop through these type of URLs www.example.com/used-cars/location/new-york/model/bmw & www.example.com/used-cars/model/mercedes-benz and push them into a sitemap.

    add_filter( 'bwp_gxs_external_pages', 'bwp_gxs_external_pages', 10, 1 );
    function bwp_gxs_external_pages($pages)
    {
        $models = get_terms( array(
            'taxonomy' => 'vehicle_model',
            'hide_empty' => false,
        ) );
        $locations = get_terms( array(
            'taxonomy' => 'vehicle_location',
            'hide_empty' => false,
        ) );
    
        // Loop through the search terms
        foreach ( $models as $model ) {
                $pages[] = array(
                'location' => home_url( '/used-cars/model/' . $model->slug ),
                'lastmod' => '27/04/2017',
                'frequency' => 'auto',
                'priority' => '0.8'
            );
            foreach ( $locations as $location ) {
                $pages[] = array(
                    'location' => home_url( '/used-cars/location/' . $location->slug . '/model/' . $model->slug ),
                    'lastmod' => '27/04/2017',
                    'frequency' => 'auto',
                    'priority' => '0.8'
                );
            }
    
        }
    
       return $pages;
    }

    So a problem I encounter with this code is that, when I set the hide_empty to true, I get only URLs with posts assigned to them, but then when I set it to false as it is in the code, I get a WSOD.

    So my guess is that, the problem lies with get_terms

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get terms() alternative’ is closed to new replies.