I did some searching and I was able to find a couple of things which maybe related to this issue I am having.
I tried using the code provided in the documents in my functions.php file
$connected = new WP_Query( array(
'connected_type' => 'posts_to_anime',
'connected_items' => get_queried_object(),
'nopaging' => true,
) );
$animetitle;
while ( $connected->have_posts() ) : $connected->the_post();
$animetitle = get_the_title();
if (isset($animetitle)) {
break;
}
endwhile;
This code should grab the first connection it finds and then break out of the loop and subsequently store that connections title into the $animetitle variable. However, I am using this in the following function
function my_acf_save_post( $post_id )
{
// vars
$episode_number = get_field('anime_episode_number' , $post_id );
if( $episode_number )
{
remove_action('acf_save_post' , 'my_acf_save_post' , 20);
$connected = new WP_Query( array(
'connected_type' => 'posts_to_anime',
'connected_items' => get_queried_object(),
'nopaging' => true,
) );
$animetitle;
while ( $connected->have_posts() ) : $connected->the_post();
$animetitle = get_the_title();
if (isset($animetitle)) {
break;
}
endwhile;
$my_post = array();
$my_post['ID' ] = $post_id;
$my_post['post_title'] = $animetitle." Online Episode ".$episode_number;
$my_post['post_name'] = $animetitle."-online-episode-".$episode_number;
wp_update_post( $my_post );
}
}
// run before ACF saves the $_POST['fields'] data
add_action('acf_save_post' , 'my_acf_save_post' , 20);
This function uses fields from another addon and couple of static words to set the post title and post slug. I just want to be able to use the connected post title’s name into the post that is being created as you can see by the code above.
Of course this is giving me an error, which I think is related to the fact that it can’t really figure out what post to check for connected items for, and the query is messing up.
Here is the error I get, by the way the error only appears if I add the extra posts 2 posts code.
Warning: Could not find direction(s). in /home2/asdf/public_html/wp-content/plugins/posts-to-posts/core/query-post.php on line 16
Warning: Cannot modify header information - headers already sent by (output started at /home2/asdf/public_html/wp-content/plugins/posts-to-posts/core/query-post.php:16) in /home2/asdf/public_html/wp-includes/pluggable.php on line 876
I just want to figure out what is called by posts 2 posts or what not when the post is created. That way I could probably use that to grab the post title of the connected post and embed it into the post title of the post that’s being created.