Support

Account

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?