Skip Navigation

[Resolved] Missing Term Fields on Custom Taxonomy Archive Pages

This thread is resolved. Here is a description of the problem and solution.

Problem:
Client is outputting term meta fields outside the loop on a custom taxonomy archive, but the term fields are not displaying.

Solution:
They should, and it appears to be an issue introduced in Types 3.0 which is still being investigated. In the meantime you can register the following custom shortcode (by add this code to your theme's functions.php file):

add_shortcode( 'taxonomy', function( $atts ){
 
    global $wp_query;
    $tax = $wp_query->get_queried_object();
 
    if ( isset( $atts['field'] ) ) {
        $content = get_term_meta( $tax->term_id, $atts['field'], true );
    } else {
        $content = "";
    }
 
    return $content;
});

Then use it in the custom archive like so:

[taxonomy field="wpcf-term-field-slug"]
This support ticket is created 6 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 4 replies, has 2 voices.

Last updated by chrisB-30 6 years, 6 months ago.

Assisted by: Nigel.

Author
Posts
#902746

Hello,

I am creating a dating site using toolset. The dating profiles (entries) are sorted into regions and countries.

Here is how it is arranged:

Post Type = Brides
Taxonomy = Locations

Currently for each "Location" I am using a wordpresss page with a view short-code inserted at the top to display a grid of entries for that particular location. And below that I have an article about the specific country. You can see an example here:

hidden link

I have about 50 pages/countries and I have created a page and a view for each and every country.

It now appears that this may not be the ideal way to structure my site for several reasons - including the inability to create breadcurmbs.

I was thinking about changing my structure and just using the location archive page for each location instead of using a WordPress Page.

The problem is that there is no way to enter the article on the location archive pages below the grid of entry images.

Here is what I tried…

I created a layout and applied it to the location archive, and in the layout I inserted a view to display a grid of images/entries from that specific category - but I do not see a way to display the article below the entry grid.

Here is an example of a Location taxonomy page:

hidden link

And here are the elements I am using:

Layout = Layout for Bride Archives
View = Bride Master View

In the layout editor, underneath the grid of entries - I inserted a visual editor field - but it does not show up on the taxonomy/location edit page.

I also tried using the "Description" box on the taxonomy edit page to enter my article but it displays above the grid of images, and it does not have the full blown text formatting options - which I really need.

Any suggestions?

#902937

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Chris

I'm not surprised you struggled a little with this, we don't actually support displaying taxonomy fields on taxonomy archive pages (I have submitted a feature request about this).

Here's what I suggest.

Create a custom field group for your location taxonomy and add a WYSIWYG field, something like "country-details".

Edit your location terms and reproduce the content that you currently have in pages in this country-details term field.

Now edit the Layout that is assigned to your location taxonomy archive and insert a Visual Editor cell where you want to display these country details.

You'll need to use a custom shortcode (which we will register in a moment), like so:

[taxonomy field="wpcf-country-details"]

Note that Types stores custom fields with a 'wpcf-' prefix.

Now let's register a custom shortcode to output the content of the field you specify in that field attribute. Add the following to your theme's functions.php file (or use a plugin such as Code Snippets):

add_shortcode( 'taxonomy', function( $atts ){

	global $wp_query;
	$tax = $wp_query->get_queried_object();

	if ( isset( $atts['field'] ) ) {
		$content = get_term_meta( $tax->term_id, $atts['field'], true );
	} else {
		$content = "";
	}

	return $content;
});

You should then see that WYSIWYG field output when you visit a location archive.

On a separate note, you should be able to use the archive cell to output your posts from the archive in a grid as you are currently doing with a View. By adding a View to do this you are essentially duplicating the query that runs on this page.

#903614

Yep that did the trick... Thanks!

It is a bit of a hack on the back-end but it renders fine on the front end. Add my vote to the feature request!

The only unexpected byproduct of switching to category pages is that my URLs are not falling in line. I'm not sure if I should ask this question in this ticket or start a new one as it is a different (yet related issue) - I will ask here for expediency - just let me know if you want me to move it to a new ticket.

URL Issue

Just as a refresher here is my structure in Toolset:

Post Type = Brides
Taxonomy = Location
My locations have 2 levels (Region ie, Asian, Latin, African, Euro) and Country (ie, Colombia, Cuba etc)

My hierarchey is like this: Brides - Region - Country - Entry Title

I am using Yoast Breadcrumbs - which is creating the correct hierarchy as you can see on an entry page like this one:
hidden link

I am happy with the url structure for the entry pages as shown above - the problem is with the Region and Country pages which appear like this:
hidden link
hidden link

Is there any way to get rid of "locations" in the url so they would render as:
hidden link
hidden link

I know there are plugins for wordpress that will rewrite urls on an individual basis - but I am trying to stay away from too many hacks on my site.

I could probably live with:
hidden link
hidden link

I tried adding "brides" as a rewrite base in the location taxonomy settings but it just threw up 404 errors - I assume because it was conflicting with the brides post type.

Any ideas?

Thanks

New threads created by Nigel and linked to this one are listed below:

https://toolset.com/forums/topic/split-change-custom-taxonomy-slugs/

#903783

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Chris

I split that question off into another thread, we can close this one?

#904371

Thanks!