Skip to content

Instantly share code, notes, and snippets.

@philhoyt
Last active August 18, 2024 12:00
Show Gist options
  • Select an option

  • Save philhoyt/11ab22518aa26fedeb89867a228ea53f to your computer and use it in GitHub Desktop.

Select an option

Save philhoyt/11ab22518aa26fedeb89867a228ea53f to your computer and use it in GitHub Desktop.

Revisions

  1. philhoyt revised this gist Apr 29, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions advanced-custom-fields-post-title.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <?php
    /** Create Title and Slug */
    function acf_title( $value, $post_id, $field ) {
    if ( get_post_type( $post_id ) === 'staff' ) {
  2. philhoyt revised this gist Apr 29, 2022. 1 changed file with 12 additions and 11 deletions.
    23 changes: 12 additions & 11 deletions advanced-custom-fields-post-title.php
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,18 @@
    // Create Title and Slug
    /** Create Title and Slug */
    function acf_title( $value, $post_id, $field ) {
    if ( get_post_type( $post_id ) == 'staff' ) {
    if ( get_post_type( $post_id ) === 'staff' ) {

    $new_title = get_field('first_name', $post_id) . ' ' . $value;
    $new_slug = sanitize_title( $new_title );
    $new_title = get_field( 'first_name', $post_id ) . ' ' . $value;
    $new_slug = sanitize_title( $new_title );

    // update post
    wp_update_post( array(
    'ID' => $post_id,
    'post_title' => $new_title,
    'post_name' => $new_slug,
    ) );
    wp_update_post(
    array(
    'ID' => $post_id,
    'post_title' => $new_title,
    'post_name' => $new_slug,
    )
    );
    }
    return $value;
    }
    add_filter( 'acf/update_value/name=last_name', 'acf_title', 10, 3 );
    add_filter( 'acf/update_value/name=last_name', 'acf_title', 10, 3 );
  3. philhoyt created this gist Dec 13, 2016.
    17 changes: 17 additions & 0 deletions advanced-custom-fields-post-title.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    // Create Title and Slug
    function acf_title( $value, $post_id, $field ) {
    if ( get_post_type( $post_id ) == 'staff' ) {

    $new_title = get_field('first_name', $post_id) . ' ' . $value;
    $new_slug = sanitize_title( $new_title );

    // update post
    wp_update_post( array(
    'ID' => $post_id,
    'post_title' => $new_title,
    'post_name' => $new_slug,
    ) );
    }
    return $value;
    }
    add_filter( 'acf/update_value/name=last_name', 'acf_title', 10, 3 );