WordPress.org

Ready to get started?Download WordPress

Forums

Changing post_title and post_name (2 posts)

  1. pszeinert
    Member
    Posted 4 years ago #

    For a custom post type, is it possible to pass variables to change the post_title and post_name based on information located in custom post fields?

    What I have done so far is much more involved, but the gist of the problem lies here:

    $my_post_title = ($event_team ." vs. " .$event_opponent ." - " .$event_date);
    $my_post_name = sanitize_title_with_dashes($event_team ."-vs-" .$event_opponent ."-" .$event_date);
    
    	if(isset($_POST['post_type']) && ($_POST['post_type'] == "sport_event")) {
    
    		// Create post object
    		$custom_title = array();
    		$custom_title['ID'] = $this_post;
    		$custom_title['post_title'] = $my_post_title;
    		$custom_title['post_content'] = 'This is a custom post of the sport_event type. If you can see this text, something is wrong';
    		$custom_title['post_name'] = $my_post_name;
    }

    I have tried the save_post, wp_insert_post, wp_insert_post_data, and a few others. The ones that work to update the database create an infinite loop and add a few hundred post drafts. The ones that stop short of initiating an infinite loop fail to change the values in the database.

    The alternative would be to create custom fields and treat them as the post_title and post_name, but for reasons I won't bother with here, that solution would not be preferred.

  2. pszeinert
    Member
    Posted 4 years ago #

    As an alternative, does anyone know which part of the core has the code for saving the post title?

    Don't worry, I'm not planning on hacking the core, I just need to know where the vales are called and saved to the DB so I can inject my variables from the functions.php file.

Topic Closed

This topic has been closed to new replies.

About this Topic