ポスト クエリが を呼び出している可能性が高いsetup_postdataため<!--nextpage-->、機会を得る前に既に置き換えられているため、別のフィルターを使用するか、Wordpress が何を挿入しているかを把握する必要があります。の代わりにget_postsを使用すると、the_content前に取得できます。理想的には、これより前に発生するフィルターを見つけることができますが、DB 書き込みの前ではありませんが、仕事をするものを見つけることができないようです。setup_postdataWP_querythe_content
印刷する直前ではなく、破壊的(データベースに保存する前にタグを置き換える)であるという点で美しくありませんが、これはうまくいくかもしれません:
function reformat_lists($content){
$f = '<!--nextpage-->';
$r = '<div id="cmn-list">';
$content = str_ireplace($f,$r,$content); //don't forget to pass your replaced string to $content
return $content;
}
add_filter( 'content_save_pre', 'reformat_lists');
編集:さらに良いことに、 を取得するglobal $postと、フィルタリングされていないコンテンツを取得できます。以下を試してください - コンテンツの最後に を追加して</div>、挿入するコンテンツを閉じ、レイアウトが崩れないようにしました。グラブはglobal $postすべてのコンテキストで機能するとは限らないため、セットアップでテストするためにそのままにしておきます.
function reformat_lists($content){
global $post;
$content = $post->post_content;
$f = '<!--nextpage-->';
$r = '<div id="cmn-list">';
$content = str_ireplace($f,$r,$content) . '</div>';
return $content;
}
add_filter( 'the_content', 'reformat_lists', 1);