[Resolved] Programmatically set all pages up to use sections?

Home Forums Support [Resolved] Programmatically set all pages up to use sections?

Home Forums Support Programmatically set all pages up to use sections?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #295826
    Katie Jones

    Hi all,

    Has anyone developed code to programmatically set up all pages to use sections? I have a site with 40+ pages where I’d like to, for each page, set the page to use sections, and create a first section with the content from the post content. Does this exist somewhere already?

    Thanks!

    Katie

    #295849
    Tom
    Lead Developer
    Lead Developer

    Hi Katie,

    I’m afraid this doesn’t currently exist. The Sections settings would also need to be set up etc.. automatically.

    #295852
    Katie Jones

    Thanks, Tom. Any reason you can think of that this can’t be done programmatically, or would be especially difficult?

    I dug into how this works in the db maybe a year ago but I’ve forgotten. Seems like I might have tried this back then and ran into something unexpected though I don’t remember what or why that would be.

    #295862
    Tom
    Lead Developer
    Lead Developer

    You would basically have to loop through each of your posts:

    $posts = get_posts();
    foreach ( $posts as $post ) {
    
    }

    get_posts: https://codex.wordpress.org/Template_Tags/get_posts

    Then in there, update the post meta to turn sections on:

    update_post_meta( $post->ID, '_generate_use_sections', array( 'use_sections' => 'true' ) );

    Totally untested, but theoretically that should turn Sections on within each page you looped through.

    The hard part is taking your content from the default editor, and adding it into the first section. I don’t know how to do that off the top of my head, would take quite a bit of trial and error to figure out.

    #295889
    Katie Jones

    Hmm, maybe that second bit was the part I tripped on last time. Okay, I’ll likely be trying this, if I do get it working I’ll post my code. Thanks, Tom!

    #296104
    Tom
    Lead Developer
    Lead Developer

    Sounds good! 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.