{"id":13773453,"url":"https://github.com/jgraup/advanced-custom-fields-nav-menu-field","last_synced_at":"2025-05-11T05:34:40.558Z","repository":{"id":20360575,"uuid":"23635735","full_name":"jgraup/advanced-custom-fields-nav-menu-field","owner":"jgraup","description":"Adds Navigation Menus to Advanced Custom Fields (ACF V5)","archived":false,"fork":false,"pushed_at":"2017-01-20T19:29:53.000Z","size":22,"stargazers_count":57,"open_issues_count":2,"forks_count":14,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-17T08:44:24.010Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jgraup.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-03T20:11:24.000Z","updated_at":"2024-02-26T22:41:02.000Z","dependencies_parsed_at":"2022-08-03T03:15:49.109Z","dependency_job_id":null,"html_url":"https://github.com/jgraup/advanced-custom-fields-nav-menu-field","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgraup%2Fadvanced-custom-fields-nav-menu-field","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgraup%2Fadvanced-custom-fields-nav-menu-field/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgraup%2Fadvanced-custom-fields-nav-menu-field/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgraup%2Fadvanced-custom-fields-nav-menu-field/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jgraup","download_url":"https://codeload.github.com/jgraup/advanced-custom-fields-nav-menu-field/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253523689,"owners_count":21921815,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T17:01:15.789Z","updated_at":"2025-05-11T05:34:35.545Z","avatar_url":"https://github.com/jgraup.png","language":"PHP","funding_links":[],"categories":["Third-Party Add-Ons"],"sub_categories":[],"readme":"# Advanced Custom Fields: Nav Menu Field #\n\nThis is an [Add-On plugin](http://wordpress.org/extend/plugins/advanced-custom-fields/)  [*](http://support.advancedcustomfields.com/forums/forum/add-ons/user-submitted/) [*](https://github.com/reyhoun/awesome-acf) for Advanced Custom Fields (ACF) [4](http://www.advancedcustomfields.com/) \u0026 [Pro 5](http://www.advancedcustomfields.com/pro) that adds a 'Nav Menu' Field type, allowing you to select from the [menus](http://codex.wordpress.org/Navigation_Menus) you create in the WordPress Admin backend to use on your website's frontend. \n\n![](http://faisonz.com/wp-content/uploads/2014/01/acf-nav-menu-field-banner-770x250.png)\n\n\nUsing ACF, you can set the Nav Menu Field to return the selected menu’s:\n\n| Return Value   | When to use  |\n| ------ | ------------ |\n| ID     | for lightweight coding |\n| Object | for more involved programming  |\n| HTML   | (generated from [wp_nav_menu](http://codex.wordpress.org/Function_Reference/wp_nav_menu)) for quickly displaying a menu  |\n\n\n## ACF 4 \u0026 Pro 5\n\nThis version adds support for [ACF Pro 5](http://www.advancedcustomfields.com/pro) to the exisiting [Nav Menu Field plugin](http://wordpress.org/plugins/advanced-custom-fields-nav-menu-field/) by [Faison Zutavern](http://faisonz.com/wordpress-plugins/advanced-custom-fields-nav-menu-field/)  [@Faison](https://github.com/Faison) [@FaisonZ](https://twitter.com/FaisonZ/).\n\n## UPDATED (10/15/2014)\n\nThe original vesion has been updated to include support for ACF 5 Pro. Now you can update directly from WP at [Nav Menu Field plugin page](http://wordpress.org/plugins/advanced-custom-fields-nav-menu-field/) or follow the discussion on the WP Support Forum: [Advanced Custom Fields: Nav Menu Field\n[resolved] ACF 5 compatibility](https://wordpress.org/support/topic/acf-5-compatibility). Since this repo was created to add new functionality, I would recommend using the original version since it will most likely have better support moving forward. If you don't really care or just want to see some examples then please continue to read on.\n\n## Example\n\n1. Set up your ACF in the backend and select \"Nav Menu ID\" as the Return Value\n2. On a page or post, select your menu from the dropdown and update the entry\n3. Then get the menu you always wanted with:\n\n````php\n// Your post id\n$post_id = 259; \n\n// Your ACF field id\n$acf_field_id = 'sidebar_menu'; \n\n// Get the menu id\n$field = get_field($acf_field_id, $post_id);  // ID\n\n$titles = array();\n\nif(!empty($field)){\n\n  // Assuming we selected \"Nav Menu ID\" as our return type\n  // Get the menu object\n  $items = wp_get_nav_menu_items($field);\n  \n  if($items){\n    $titles = wp_list_pluck($items, 'title');\n  }\n}\n\n// Now do something with the titles\necho implode (\" / \", $titles);\nprint_r($titles);\nerror_log(json_encode($items));\n````\n\n## Example\n\nThis example shows how you can dynamically check the Return Value before acting on the data.\n\n````php\nclass NavFieldTypes\n{\n\tconst UNKNOWN = -1;\n\tconst OBJECT = 0;\n\tconst HTML = 1;\n\tconst ID = 2;\n}\n\n// Your post id\n$post_id = 2; \n\n// Your ACF field id\n$acf_field_id = 'sidebar_menu'; \n\n// Get the menu id\n$field = get_field($acf_field_id, $post_id);  // Object | HTML | ID\n\n// We don't know the type yet\n$field_type = NavFieldTypes::UNKNOWN;\n\n// Let's find out...\nif(is_object($field)) \n\t$field_type = NavFieldTypes::OBJECT; \nelse if (is_scalar($field)){\t\n\t$field_type = !is_numeric($field) ? \n\t\tNavFieldTypes::HTML : NavFieldTypes::ID;\t \n} \n\n// OK, based on what we know we should...\nswitch ($field_type)\n{\t\n  case NavFieldTypes::OBJECT:\n\t\n\t// $field -\u003e {ID,name,slug,count}\n\t\n\techo \"OBJECT: {$field-\u003ename} | \"; \n\t$items = wp_get_nav_menu_items($field-\u003eID);\n\t$wrapItem = function ($ID, $title)\n\t{\n\t\treturn \"\u003ca href='#{$ID}'\u003e{$title}\u003c/a\u003e\";\n\t};\n\techo implode (\" / \", array_map($wrapItem, \n\t\twp_list_pluck($items, 'ID'), \n\t\twp_list_pluck($items, 'title')));\n    break;\n\t\n  case NavFieldTypes::HTML:\n\t\n\techo \"HTML: \" . $field;\n    break;\n\t\n  case NavFieldTypes::ID:\n\t\n\techo \"ID: {$field} | \"; \n\t$items = wp_get_nav_menu_items($field);\n\techo render_nav_menu_items($items);\n    break;\n\t\n  default:\n\t// Nothing to see here\n}\n\nfunction render_nav_menu_items($items){\n\tob_start();\n\tif($items){\n\t\t$titles = array();\n\t\tforeach($items as $key =\u003e $value){\n\t\t\t$titles[] = $value-\u003etitle;\n\t\t}\n\t\techo implode (\" / \", $titles);\n\t}\n\treturn ob_get_clean();\n}\n````\n\n## Links\n\n* [Original ACF 4 Plugin](http://wordpress.org/plugins/advanced-custom-fields-nav-menu-field/)\n* [ACF 4 on WordPress.org](http://wordpress.org/plugins/advanced-custom-fields/)\n* [ACF 4](http://www.advancedcustomfields.com/)\n* [ACF Pro 5](http://www.advancedcustomfields.com/pro)\n* [ACF Support Forum: User Submitted Thread : Nav Menu Field] (http://support.advancedcustomfields.com/forums/topic/nav-menu-field/)\n* [Creating an ACF Plugin](http://wordpress.org/extend/plugins/advanced-custom-fields/)\n* [Get Field in ACF](http://www.advancedcustomfields.com/resources/get_field/)\n* [Nav Menus](http://codex.wordpress.org/Navigation_Menus)\n* [Awesome Advanced Custom Field : Links](https://github.com/reyhoun/awesome-acf)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjgraup%2Fadvanced-custom-fields-nav-menu-field","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjgraup%2Fadvanced-custom-fields-nav-menu-field","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjgraup%2Fadvanced-custom-fields-nav-menu-field/lists"}