前提
■Advanced Custom Fieldsで作成したカスタムフィールドで、フィールド名が「question」
■カスタム投稿ではなく通常の投稿
■記事のタイトルは不要のため、以下の記述をfunctionへ記入済み
add_action( 'init' , 'my_remove_post_editor_support' ); function my_remove_post_editor_support() { remove_post_type_support( 'post', 'title' );//タイトル }
実現したいこと
カスタムフィールドの値を記事のタイトルへ反映させたいですのですが上手くいかず困っております。
記述した内容は以下の通りです。
該当のソースコード
function replace_post_title($title) { global $post; //post_typeを判定(post, page, カスタム投稿) if( $post->post_type == 'post' ){ if(get_field('question',$post->ID)){ $title = get_field('question',$post->ID); } } return $title; }_**### イタリックテキスト**_ add_filter('title_save_pre', 'replace_post_title');
投稿の画面に発生している問題・エラーメッセージ
Warning: Attempt to read property “post_type” on null in・・・ Warning: Cannot modify header information – headers already sent by・・・

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/08/22 09:11
2022/08/23 01:09
2022/08/23 01:11
2022/08/23 13:04
2022/08/24 00:06
2022/08/24 01:13