- This topic has 5 replies, 4 voices, and was last updated 1 year, 7 months ago by
Tom.
-
AuthorPosts
-
November 25, 2020 at 2:01 pm #1547466
Alessio Angeloro
Hi,
I’m trying to put the dropdown of the categories in the first navigation, but I don’t understand which hook to use, if I use “generate_menu_bar_items” the pages and the menu are broken.
I use this code
function city_dropdown() { ?> <select> <?php $cities_terms = get_terms('city', array('hide_empty' => '0')); foreach ( $cities_terms as $city_term ): echo '<option value="'.$city_term->name.'">'.$city_term->name.'</option>'; endforeach; } ?> </select> <?php add_action('generate_menu_bar_items','city_dropdown');
Thanks.
November 25, 2020 at 4:20 pm #1547904Elvin
StaffCustomer SupportHi,
Let’s check a few things first:
To be able to use
generate_menu_bar_items
, please refer to the video included in this brief documentation.
https://docs.generatepress.com/article/generate_menu_bar_items/As for the code:
Can you do a
var_dump($cities_terms);
of this code? To see if it works.$cities_terms = get_terms('city', array('hide_empty' => '0'));
If it returns nothing, perhaps replacing it with this would work:
$cities_terms = get_terms(array( 'taxonomy' => 'your taxonomy name', 'hide_empty' => false ));
Reference: https://developer.wordpress.org/reference/functions/get_terms/
A wise man once said:
"Have you cleared your cache?"November 25, 2020 at 10:35 pm #1548441Alessio Angeloro
array(2) { [0]=> object(WP_Term)#17672 (10) { ["term_id"]=> int(124) ["name"]=> string(6) "Milano" ["slug"]=> string(6) "milano" ["term_group"]=> int(0) ["term_taxonomy_id"]=> int(124) ["taxonomy"]=> string(4) "city" ["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(0) ["filter"]=> string(3) "raw" } [1]=> object(WP_Term)#17676 (10) { ["term_id"]=> int(122) ["name"]=> string(4) "Roma" ["slug"]=> string(4) "roma" ["term_group"]=> int(0) ["term_taxonomy_id"]=> int(122) ["taxonomy"]=> string(4) "city" ["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(1) ["filter"]=> string(3) "raw" } } array(2) { [0]=> object(WP_Term)#17672 (10) { ["term_id"]=> int(124) ["name"]=> string(6) "Milano" ["slug"]=> string(6) "milano" ["term_group"]=> int(0) ["term_taxonomy_id"]=> int(124) ["taxonomy"]=> string(4) "city" ["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(0) ["filter"]=> string(3) "raw" } [1]=> object(WP_Term)#17676 (10) { ["term_id"]=> int(122) ["name"]=> string(4) "Roma" ["slug"]=> string(4) "roma" ["term_group"]=> int(0) ["term_taxonomy_id"]=> int(122) ["taxonomy"]=> string(4) "city" ["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(1) ["filter"]=> string(3) "raw" } }
The code works, it returns a select with the values, the problem is that I don’t know which hook to use to put the select in the menu; considering that I have this option enabled :
November 26, 2020 at 5:58 am #1549505David
StaffCustomer SupportHi there,
when you say the pages and menu are broken – any chance i can see that on your site ?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/November 26, 2020 at 6:17 am #1549531Alessio Angeloro
Yes, i sent you the access in private information.
Thanks
November 26, 2020 at 12:30 pm #1550550Tom
Lead DeveloperLead DeveloperHi there,
Any chance you can un-comment the code? I’m not overly comfortable breaking your site if you’re not around to fix it.
When you say “breaking”, what do you mean exactly? Are you getting a specific error?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.