投稿の付加投稿情報が取得出来ない
-
投稿の完全削除時にサムネイルを削除する為、function.phpにコードを書きました。
下記サイトを参考にしています。
https://securavita.net/wordpress-delete_post_attachment/function delete_post_attachment( $post_id ) { /* 添付画像の削除 */ $args = array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => 'any' ); $attachments = get_children($args); foreach($attachments as $attachment) { wp_delete_post($attachment->ID); } } add_action( 'before_delete_post', 'delete_post_attachment' );
投稿には確かにサムネイル(アイキャッチ画像)を添付していますが
get_children()は空の配列を返します。
post_typeをanyに変えるなど対応してみましたが、解決しませんでした。
どのような原因が考えられますでしょうか?また、get_children()が内部的に呼び出すget_posts()についても
post_typeとpost_parentを指定したものの取得出来ませんでした。追記です。
$post_idは問題無く渡されています。
なお、テーマファイル(single.php)に記述したところ、問題無く配列が返されています。
function.php内で使用する方法はありますでしょうか?
3件の返信を表示中 - 1 - 3件目 (全3件中)
3件の返信を表示中 - 1 - 3件目 (全3件中)
- トピック「投稿の付加投稿情報が取得出来ない」には新たに返信することはできません。