Site logo

Archived topic

Custom taxonomies are not displayed in the theme.

10 replies · Started by Luiz Guilherme on June 16, 2020

Viewing posts 1–11 of 11

In the customizations screen there are only the options to display CATEGORIES AND TAGS, there is no option to display PERSONALIZED TAXONOMIES of the posts.

These taxonomies are added to both standard and custom posts.

I am interested in showing them both, but we will pay attention to the standard wordpress posts on this issue.

I have a custom Taxonomy called "Places" where I add places like: World, Brazil, or City names, I would like them to be displayed in posts along with the standard Categories.

See a post to get an idea:
https://capixabamassa.com/missao-espacial-tripulada-da-spacex-parece-cada-vez-mais-dificil-em-2019-diz-executivo/

In this post, the personalized taxonomy "World" should appear.
But only standard categories are displayed.

The link you showed me didn't help me much.

So in that case, you would do this:

add_action( 'generate_post_meta_items', function( $item ) {
    if ( 'places' === $item ) {
        $places_list = get_the_term_list( get_the_ID(), 'places', '', ', ' ); // This needs the actual taxonomy slug.

        if ( $places_list ) {
            printf(
                '<span class="tags-links">%3$s<span class="screen-reader-text">%1$s </span>%2$s</span> ',
                esc_html_x( 'Places', 'Used before tag names.', 'generatepress' ),
                $places_list,
                apply_filters( 'generate_inside_post_meta_item_output', '', 'places' )
            );
        }
    }
} );

add_filter( 'generate_footer_entry_meta_items', function( $items ) {
    $items[] = 'places';

    return $items;
} );

Hello Tom,
Worked perfectly.
Thank you very much.

As for the display of "Custom taxonomies" in "Custom post types"

How do I display?

An observation.
I am using the CPT UI to create custom post types.

Hello Tom.

First of all thank you very much for your help, things are falling into place now.

With the code that passed me above #1361063, I was able to activate the display of custom taxonomies in standard posts as desired.

And with the other code #1419264, I managed to display it in personalized posts.

But I was left with some questions, if you can help me, I'll number it here in this post to make it easy to understand and answer ok ?, so I'll know what you mean:

01 - In the custom categories display code, how would I do to display more than one? e.g. "Places" and "Segments"
Do I have to create 2 codes, one for each category?

02 - Still in this code, I customized it according to my need, replacing the "places" texts with the desired taxonomy. but what about "Places" with the first capital letter, I put several random texts there and did not see where it is displayed. the code was also unaffected, it continued to function normally.

03 - Regarding the display of taxonomies in types of personalized posts created with CPTUI.

I followed the instructions of the two links and only the "generate_footer_meta_post_types" worked.
The option: "generate_entry_meta_post_types" did not display anything.

This is the code I am using:

add_filter( 'generate_footer_meta_post_types', function( $types ) {
    $types[] = 'empresas';
    return $types;
} );

add_filter( 'generate_entry_meta_post_types', function( $types ) {
    $types[] = 'empresas';
    return $types;
} );

You see an example page here:
https://capixabamassa.com/empresas/delaitv-2/

04 - In the example shown, there are two options;

$ types [] = 'my-post-type';
$ types [] = 'recipes';

This second 'recipes' also refers to types of posts,
If so, wouldn't it be cool to use the pattern below in the example ?:

$ types [] = 'my-post-type1';
$ types [] = 'my-post-type2';
$ types [] = 'my-post-type ...';

05 - As it is, when I click on a personalized Taxonomy "Places" it displays all posts that have this taxonomy, regardless of whether they are standard or personalized.

I would like the results displayed to be according to the type of post the taxonomy is in.

For example:
* Clicking on a personalized taxonomy "Brazil" within a personalized post "Companies".
The results will be "Companies" that have the taxonomy "Brazil".
(Standard posts will not be displayed in this result).

* If I click on a custom taxonomy "Brazil" within a standard post the results will be "standard posts" that have the taxonomy "Brazil" (Companies will not be displayed in this result).

Sorry for taking so long, I believe this will help many other users.

Hi there,

1. You would do this:

add_action( 'generate_post_meta_items', function( $item ) {
    if ( 'places' === $item ) {
        $places_list = get_the_term_list( get_the_ID(), 'places', '', ', ' ); // This needs the actual taxonomy slug.

        if ( $places_list ) {
            printf(
                '<span class="tags-links">%3$s<span class="screen-reader-text">%1$s </span>%2$s</span> ',
                esc_html_x( 'Places', 'Used before tag names.', 'generatepress' ),
                $places_list,
                apply_filters( 'generate_inside_post_meta_item_output', '', 'places' )
            );
        }
    }

    if ( 'segments' === $item ) {
        $segments_list = get_the_term_list( get_the_ID(), 'segments', '', ', ' ); // This needs the actual taxonomy slug.

        if ( $segments_list ) {
            printf(
                '<span class="tags-links">%3$s<span class="screen-reader-text">%1$s </span>%2$s</span> ',
                esc_html_x( Segments', 'Used before tag names.', 'generatepress' ),
                $segments_list,
                apply_filters( 'generate_inside_post_meta_item_output', '', 'segments' )
            );
        }
    }
} );

add_filter( 'generate_footer_entry_meta_items', function( $items ) {
    $items[] = 'places';
    $items[] = 'segments';

    return $items;
} );

2. Not sure what you mean here - can you explain further?

3. What isn't working here? I am seeing some extra meta (additional tags) in the footer there.

4. Exactly - you can list as many custom post types there as you like.

5. I believe this sort of thing would take some pretty complex custom queries, unfortunately. WordPress itself will simply display posts inside any given taxonomy - it doesn't care about where the link was clicked/other relationships within it.

02 -
I'm talking about this part of the code 《esc_html_x ('Places',' Used before tag names. ','》 What does this word Places do?

03 -
So, did you show me 2 links, one to display above and one below? I entered the 2 codes to test, but the taxonomies were only shown below. as you can see. see that I do not want to display above and below at the same time, I would just like to understand to be able to use above when necessary.

05 -
Ok, I will try "content view pro" plugin.

2. Ah, that's help contextual text for translators - it doesn't display on the website.

3. Are you wanting the taxonomies to display up below the post title instead of after the content? Right now I'm seeing two sets of terms after the content.

Thanks

This archived topic is closed to new replies.