I am using Gravity Forms to allow users to create posts from the front end.

However, the way this site I am building is going to work, one specific Post_Type is essentially just a “Data” post. There is a specific Taxonomy who’s Terms are actually the “Title” of the data set.

I have already figured out a way to hide the “Title” field in Gravity forms but still have it present on the form (for some reason they lock the “Post_Type” and “Post Status” into the ‘Title’ field in the GUI, so I overloaded it’s conditional logic to force it to always hide).

I want to create a filter that would always copy the [Term] value for a specific [Taxonomy] into the [Title] field of a specific [Post_Type].

Any advice I could get on how to accomplish this would be great! Thanks in advance!

==============================================================

OK, using code from @Manny Fleurmond below, and from this post: Title_save_pre – Simple problem that u know for sure

I came up with

function taxonomy_title_rename($title) {
    global $post;
    $type = get_post_type($post->ID);
    if ($type== 'CUSTOM_POST_TYPE') {
            if($post->post_type === 'CUSTOM_POST_TYPE') {
        $terms = wp_get_object_terms($post->ID, 'MY_TAXONOMY');
        if(!is_wp_error($terms) && !empty($terms)) {
            $title = $terms[0]->name;
        }
        }
    return $title;
}
     else if ($type != 'CUSTOM_POST_TYPE') {
       return $title;
    }
    }
    add_filter ('title_save_pre','taxonomy_title_rename');

This is actually saving the post title to the post from the taxonomy. However, it is not then pulling it into the permalink as well, my permalink is just the post ID number. Will see if I can get this solved on my own, but any help would be appreciated!

3 Answers
3

I’ve pieced together a solution. Let me know if it’s what you need:

add_filter('the_title','term_filter',10,2);
function term_filter($title, $post) {
    $post = get_post($post) ;
    if($post->post_type === 'special_post_type') {
        $terms = wp_get_object_terms($post->ID, 'taxonomy');
        if(!is_wp_error($terms) && !empty($terms)) {
            $title = $terms[0]->name;
        }
    }
    return $title;
}

Basically, I’m using a filter for the title that checks what post type the title is from. If it is the correct type, the title is replaced by the first term of your taxonomy that is connected to that post.

Ask me any questions if something isn’t clear!

Leave a Reply

Your email address will not be published. Required fields are marked *