0

I'm building a WP website for a client that require location pages to be added on a frequent basis. I wanted to created a parent location page that would have the full list of locations that would automatically update each time a child page is added. Currently I'm using a custom menu, however I dont think this will automatically update each time a [location] page is added. Ideally, I would like to have an accordion on the parent page with the UK split into North East, North West etc, then under each accordion the list of the location pages that fall under that catergory. Does anyone know of a way to get these to automatically update?

Thanks

2 Answers 2

0

You can use the function wp_list_pages. If the default output isn't enough you can write a custom walker for that function.

0

You can do this by adding a custom taxonomy to your [location] pages. You can then use this custom taxonomy to put your posts in the appropriate sections of the accordion.

$args = array(                                      // Array can be extended with additional arguments
   'tax_query' => array(
       array(
           'taxonomy' => 'your-location-taxonomy',  // Name of your custom taxonomy
           'field' => 'location',                   // Name of the field in your taxonomy
           'terms' => 'North East',                 // Value of the field in your taxonomy
       )
    )
);

// Execute your query with the given arguments.
$query = new WP_Query( $args );

// Check that we have query results.
if ( $query->have_posts() ) {

    // Start looping over the query results.
    while ( $query->have_posts() ) {

        $query->the_post();

        // Build your accordion elements here

    }

}

// Restore original post data.
wp_reset_postdata();

You could wrap above code in a loop through all potential values of the location taxonomy field.

More on Taxonomies and WP_Query can be found at the respective links

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.