Home › Forums › ACF PRO › Problems with Sub Options pages › Reply To: Problems with Sub Options pages
What I ended up doing was creating a new “Page Defaults” custom post type. If a the template can’t find a value on it’s own page then it checks for a slug which matches it’s post type and get’s the ID. Then checks to see if the field exists on that page.
So in functions.php:
function the_slug_exists($post_name, $post_type = "page") {
global $wpdb;
if($slug_id = $wpdb->get_var("SELECT ID FROM wp_posts WHERE post_name = '" . $post_name . "' AND post_type = '" . $post_type . "'")) {
return $slug_id;
} else {
return false;
}
}
Then in my template:
$pt = get_post_type();
$default_id = the_slug_exists($pt, 'default_layouts');
if ( have_rows('body_content') ) {
$body_id = null;
} else {
$body_id = $default_id;
}
if( have_rows('body_content', $body_id ) ) {
while ( have_rows('body_content', $body_id ) ) {
//As normal...
It’s working, but it’s less than graceful. I’ve effectively made an options page with sub pages that works how I needed it.
Elliot… can something like this be built in?
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.