• Just noticed the thread about the sub-forum so I will resubmit.

    I have posted two other threads related to this issue, but sadly it seems to be over the head of some of the best minds on here since I have had zero replies.

    My current method is as follows:

    add_action ('wp_insert_post','save_title',99,2);
    
    	function save_title($post_ID, $post) {
    
    		global $post;
    
    		if (isset($postid)) {
    			$this_post = $postid;
    		} else {
    			$this_post = "";
    		}
    
    		$custom = get_post_custom($this_post);
    		$event_team = $custom["event_team"][0];
    		$event_opponent = $custom["event_opponent"][0];
    		$event_date = $custom["event_date"][0];
    
    		$my_post_title = ($event_team ." vs. " .$event_opponent ." - " .$event_date);
    		$my_post_name = sanitize_title($event_team ."-vs-" .$event_opponent ."-" .$event_date);
    
    		$post = array(
    			'ID' => $this_post, //Are you updating an existing post?
    			'post_content' => 'This is a custom post of the sport_event type. If you can see this text, something is wrong', //The full text of the post.
    			'post_name' => $my_post_name, // The name (slug) for your postet the status of the new post.
    			'post_title' => $my_post_title
    		); 
    
    		// Insert the post into the database
    		return $post;
    
    	}

    My previous attempts at automatically writing the post_title are located here and here.

    Help would be much appreciated. I am having to hand type the titles for this season, but I would like to make this user friendly for next year.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Sorry I don’t have the answer but I would also try over on the stack exchange site: https://wordpress.stackexchange.com/

    You have a mistake right at the start of your funciton…

    function save_title($post_ID, $post) {
    
    		global $post;
    
    		if (isset($postid)) {
    			$this_post = $postid;
    		} else {
    			$this_post = "";
    		}

    The function has two incoming variables, $post_ID and $post, a few lines down you then check if $postid is set .. but that’s a different variable, and it’s not globalised, nor declared, so it’s always going to be empty/null/false ..

    I’d guess these lines..

    //
    		if (isset($postid)) {
    			$this_post = $postid;

    Should actually read..

    //
    		if (isset($post_ID)) {
    			$this_post = $post_ID;

    Not sure if that fully addresses your problem, but hope it helps all the same.. ??

    Thread Starter pszeinert

    (@pszeinert)

    I appreciate the replies. I worked on this for another 8 hours yesterday and the code has changed significantly since I posted it, so I created a new thread.

    I was experiencing many recursion and version issues, but I have now simplified it to a more manageable chunk.

    I will close this as resolved since it was poor code to begin with.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Trying to save post_title in custom post’ is closed to new replies.