Home › Forums › Pro Support › display only main cateory (meta terms)
- This topic has 11 replies, 4 voices, and was last updated 2 years, 4 months ago by
elvin.
-
AuthorPosts
-
January 31, 2019 at 10:04 pm #7535
Alessio
Participanthi tom,
when I enable meta > include terms, multiple categories are displayed (when a post has multiple categories)
would it be possible to limit the display only to the main category? if yes… please help 🙂thank you for your great plugin
alexFebruary 1, 2019 at 5:32 pm #7552Tom
KeymasterHey Alex,
How is the main category determined? The first one to show up?
Let me know 🙂
February 1, 2019 at 7:05 pm #7555Alessio
Participanthi tom,
thank you for your reply. as most of our posts belong to more than one category (or sub-category), I would like to only show one in order to keep the meta always only on one line and not on several lines as it happens now. which one is the main category is not really important as long as it is only one. the easiest to achieve, will be enough for us 🙂
thank you again
alexFebruary 3, 2019 at 10:39 am #7584Tom
KeymasterHey Alex,
Give this a shot:
add_filter( 'wpsp_terms_output', function() { $all_terms = get_the_terms( get_the_ID(), 'category' ); $first_term = $all_terms[0]; $url = get_term_link( $first_term->term_id ); return sprintf( '<span class="wp-show-posts-terms wp-show-posts-meta"><a href="%1$s">%2$s</a></span>', $url, $first_term->name ); } );
Let me know 🙂
February 3, 2019 at 12:29 pm #7585Alessio
Participanthey tom,
thank you for your help
unluckily, when I add the snippet, i receive the following error displayed where the category should appearNotice: Undefined variable: settings in /home/xxx/public_html/xxx/wp-content/plugins/code-snippets/php/snippet-ops.php(361) : eval()’d code on line 2
alex
February 3, 2019 at 7:27 pm #7588Tom
KeymasterSorry about that – can you try again?: https://wpshowposts.com/support/topic/display-only-main-cateory-meta-terms/#post-7584
February 3, 2019 at 7:39 pm #7592Alessio
Participanttried, but unluckily different error message
Fatal error: Uncaught Error: Cannot use object of type WP_Error as array in /home/xxx/public_html/xxx/wp-content/plugins/code-snippets/php/snippet-ops.php(361) : eval()’d code:3 Stack trace: #0 /home/xxx/public_html/xxx/wp-includes/class-wp-hook.php(286): {closure}(‘<span class=”wp…’) #1 /home/xxx/public_html/xxx/wp-includes/plugin.php(203): WP_Hook->apply_filters(‘<span class=”wp…’, Array) #2 /home/xxx/public_html/xxx/wp-content/plugins/wp-show-posts/inc/functions.php(104): apply_filters(‘wpsp_terms_outp…’, ‘<span class=”wp…’) #3 /home/xxx/public_html/xxx/wp-content/plugins/wp-show-posts/inc/functions.php(133): wpsp_meta(‘below-title’, Array) #4 /home/xxx/public_html/xxx/wp-includes/class-wp-hook.php(286): wpsp_add_post_meta_after_title(Array) #5 /home/xxx/public_html/xxx/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array) #6 /home/xxx/public_html/xxx/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #7 /home/ in /home/xxx/public_html/xxx/wp-content/plugins/code-snippets/php/snippet-ops.php(361) : eval()’d code on line 3
February 4, 2019 at 6:47 pm #7615Tom
KeymasterJust made another change: https://wpshowposts.com/support/topic/display-only-main-cateory-meta-terms/#post-7584
Let me know 🙂
February 4, 2019 at 6:52 pm #7619Alessio
ParticipantYES 🙂
thank you very much Tom, working perfecty
AlessioFebruary 6, 2019 at 8:49 pm #7653Tom
KeymasterGlad I could help 🙂
July 18, 2021 at 2:10 pm #32155Brandon
ParticipantHey Tom,
I tried adding this https://wpshowposts.com/support/topic/display-only-main-cateory-meta-terms/#post-7584 but it’s giving me a critical error on the site… I’m looking to display the last child essentially of the taxonomy term string.. not sure what I am doing wrong.
Thanks
July 18, 2021 at 6:03 pm #32182elvin
ModeratorHi Brandon,
Can you share the error message you’re getting? For us to have a clearer idea on which way to point you to. 😀
Let us know. 😀
-
AuthorPosts
- You must be logged in to reply to this topic.