Support

Account

Forum Replies Created

  • Hmmm that’s too bad.

    Final update: an empty array did not completely work. Somehow leaving it empty made it impossible to actually publish the post (status remained “draft”) so I filled it with some dummy text and now it does what it should do. This issue must be somewhere deep in the WP code.

    Really not happy about the fact that I do not understand why it works because I have the feeling it will bite me in the ass at some point, but at least it does work.

    Thanks for the help!

  • Okay John, this really helped a lot and pointed me in the right direction. After some testing I managed to get it working, however I do not understand why it works… My process:

    1) I implemented exactly as you suggested. However nothing happened..
    2) I thought it might be that the day_post array was not filled correctly so I tried printing that using print_r

    Using wp_update_post:

    $my_post = array ();
    	'ID'		=> $relatie,
    	'post_content'	=> $day_post. '<br>' . $relatie );
    wp_update_post($my_post);

    3) I started checking whether this was an issue of scope so put the declaration of the day_post outside of the function, but it did not make a difference

    4) Then I checked whether it had something to do with how print_r worked and made sure it was a returned value:

    $results = print_r($day_posts, true);
    $results1 = print_r($relatieID, true);
    	$my_post = array ();
    		'ID'		=> $relatie,
    		'post_content'	=> $results . '<br>' . $relatie . '<br>' . $results1);
    
    wp_update_post($my_post);

    This actually showed that $day_post was filled correctly and that $relatie also was the correct input post.

    5) only then I saw that it had already worked! However I had no idea why so I started tracing back. Long story short: adding a `wp_update_post’ with an empty array did the trick. I suspect it has something to do with priority of what’s loaded on the page or something… but really have no idea.

    Final working code:

    $day_posts = array();
    	 foreach ($week as $weekday) {
    		$PostID = wp_insert_post(array(
    			'post_title' 	=> $latestpost[0]->post_title . ': ' . $weekday,
    			'post_type'	=> 'palaver',
    			'query_var'	=> true
    			));
    		$day_posts[] = $PostID;
    		wp_set_object_terms($PostID, $CatTermID, 'gebied');
    
    			}
    		$my_post = array ();
    		wp_update_post($my_post);
    		update_field('field_5eea245f36217', $day_posts, $relatie);
    

    If you can shed any light on this John (just because I’m interested in undertanding what’s actually happening), that would be awesome. If you have better things to do I also understand 😉 Muchas Gracias! 🙂

Viewing 2 posts - 1 through 2 (of 2 total)