Skip to content

Instantly share code, notes, and snippets.

@racmanuel
Forked from rveitch/sync_acf_post_title.php
Created December 7, 2022 21:40
Show Gist options
  • Select an option

  • Save racmanuel/dd207966a6cea60d51bd42263e00fed5 to your computer and use it in GitHub Desktop.

Select an option

Save racmanuel/dd207966a6cea60d51bd42263e00fed5 to your computer and use it in GitHub Desktop.

Revisions

  1. @rveitch rveitch revised this gist Dec 18, 2017. No changes.
  2. @rveitch rveitch revised this gist May 15, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions sync_acf_post_title.php
    Original file line number Diff line number Diff line change
    @@ -7,8 +7,8 @@
    */
    function sync_acf_post_title($post_id, $post, $update) {

    $acf_title = get_field('my_acf_field_name'); // NOTE: enter the name of the ACF field here
    if ($title) {
    $acf_title = get_field('my_acf_field_name', $post_id); // NOTE: enter the name of the ACF field here
    if ( $title ) {
    $title = $acf_title;
    } else {
    $title = $post->post_title;
  3. @rveitch rveitch revised this gist May 15, 2017. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions sync_acf_post_title.php
    Original file line number Diff line number Diff line change
    @@ -5,8 +5,7 @@
    * Triggers on save, edit or update of published posts.
    * Works in "Quick Edit", but not bulk edit.
    */
    function sync_acf_post_title($post_id, $post, $update)
    {
    function sync_acf_post_title($post_id, $post, $update) {

    $acf_title = get_field('my_acf_field_name'); // NOTE: enter the name of the ACF field here
    if ($title) {
  4. @rveitch rveitch revised this gist May 15, 2017. 1 changed file with 19 additions and 18 deletions.
    37 changes: 19 additions & 18 deletions sync_acf_post_title.php
    Original file line number Diff line number Diff line change
    @@ -5,22 +5,23 @@
    * Triggers on save, edit or update of published posts.
    * Works in "Quick Edit", but not bulk edit.
    */
    function sync_acf_post_title( $post_id, $post, $update ) {

    $acf_title = get_field('my_acf_field_name'); // NOTE: enter the name of the ACF field here
    if ( $title ) {
    $title = $acf_title;
    } else {
    $title = $post->post_title;
    }

    $content = array(
    'ID' => $post_id,
    'post_title' => $title,
    );
    remove_action( 'save_post', 'sync_acf_post_title' ); // prevent a loop
    wp_update_post( $content );

    add_action( 'save_post', 'sync_acf_post_title' );
    function sync_acf_post_title($post_id, $post, $update)
    {

    $acf_title = get_field('my_acf_field_name'); // NOTE: enter the name of the ACF field here
    if ($title) {
    $title = $acf_title;
    } else {
    $title = $post->post_title;
    }

    $content = array(
    'ID' => $post_id,
    'post_title' => $title
    );
    remove_action('save_post', 'sync_acf_post_title'); // prevent a loop
    wp_update_post($content);

    add_action('save_post', 'sync_acf_post_title');
    }
    add_action( 'save_post', 'sync_acf_post_title', 10, 3 );
    add_action('save_post', 'sync_acf_post_title', 10, 3);
  5. @rveitch rveitch created this gist May 15, 2017.
    26 changes: 26 additions & 0 deletions sync_acf_post_title.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    <?php
    /**
    * Update Post Title from an ACF field value on post save.
    *
    * Triggers on save, edit or update of published posts.
    * Works in "Quick Edit", but not bulk edit.
    */
    function sync_acf_post_title( $post_id, $post, $update ) {

    $acf_title = get_field('my_acf_field_name'); // NOTE: enter the name of the ACF field here
    if ( $title ) {
    $title = $acf_title;
    } else {
    $title = $post->post_title;
    }

    $content = array(
    'ID' => $post_id,
    'post_title' => $title,
    );
    remove_action( 'save_post', 'sync_acf_post_title' ); // prevent a loop
    wp_update_post( $content );

    add_action( 'save_post', 'sync_acf_post_title' );
    }
    add_action( 'save_post', 'sync_acf_post_title', 10, 3 );