Alright you were correct Elliot, it didn’t like being fired on init, and the other part of the problem seemed to be my use of the following filter along with the acf_add_options_sub_page()
add_filter( 'acf/options_page/settings', array( $this, 'acf_options_page_title' ) );
Not sure if this filter is now deprecated with the 1.1.0 updates or not but they didn’t play well together. Ended up just using the acf_set_options_page_title()
and acf_add_options_sub_page()
tags, not in init, and everything then works fine.
Thanks Elliot!
So actually, I think it’s probably an issue somewhere in my core functionality plugin, as when I deactivated that and have the function in functions.php, the sub-page did work and showed the fields.
So I need to figure out what is killing it. Ok, I believe you are blameless 🙂 I’ll report back with any findings if it could be a common gotcha for other people.
Thanks for you excellent and responsive support as always, Elliot.
Ryan
Hmm when I try that (both), the sub-pages don’t even show up under the custom post types:
// Financial Reports Archive Options
acf_add_options_sub_page( array(
'title' => 'Financial Archive Content',
'parent' => 'edit.php?post_type=tgf-financials',
'capability' => 'manage_options'
) );
// Grants Archive Options
acf_add_options_sub_page( array(
'title' => 'Grants Archive Content',
'parent' => 'edit.php?post_type=tgf-grants',
'capability' => 'manage_options'
) );
Hey Elliot, been digging around some more. It seems as if when I don’t specify a slug, a slug isn’t being created for the page, and when I look at the sub-page url for the given page this is the link for it: ?page
, and that is not the page title.
It’s almost as if without a slug it isn’t going through your init() checks / settings.
And then regarding fields not showing up on the options pages, it’s as if the sub-page isn’t full hooked into the various functions needed to implement the metaboxes or something. Tried debugging (eh eh), and got absolutely nothing. Just have the “No Custom field group….” flag.
Hope this provides some insight. Let me know how else I can help.
Also don’t see any js errors or anything in console
Ah my apologies, here is what I get when I print_r on $page:
Array ( [slug] => grants-archive-page-content [title] => Grants Archive Content [parent] => edit.php?post_type=tgf-grants [capability] => manage_options )
And that’s with print_r right outside the foreach
Here’s the full function:
function admin_menu()
{
// parent
if( $this->settings['show_parent'] )
{
$parent_page = add_menu_page( $this->settings['title'], $this->settings['title'], $this->settings['capability'], $this->settings['slug'], array($this, 'html'));
// actions
add_action('load-' . $parent_page, array($this,'admin_load'));
}
// sub pages
if( !empty( $this->settings['pages'] ) )
{
foreach( $this->settings['pages'] as $page )
{
$child_page = add_submenu_page( $page['parent'], $page['title'], $page['title'], $page['capability'], $page['slug'], array($this, 'html'));
// actions
add_action('load-' . $child_page, array($this,'admin_load'));
}
}
}
Hey Elliot, no problem!
Sorry no, I specified the slug to get rid of the error 🙂
Sure, tell me what to do, here is line 251:
$child_page = add_submenu_page( $page['parent'], $page['title'], $page['title'], $page['capability'], $page['slug'], array($this, 'html'));
And then of course the bigger problem is my fields not showing for these pages.
Thanks Elliot.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.