【发布时间】:2017-06-19 18:06:55
【问题描述】:
我想创建一个过滤器,默认情况下,在文件上传期间将帖子标题添加为 wordpress 中的所有图片标题。我知道为此我可以使用:
wp_insert_attachement_data
我写过类似的东西:
add_filter( 'wp_insert_attachment_data', 'wpq_insert_attachment_data', 10, 2 );
function wpq_insert_attachment_data( $data, $postarr ) {
$append = get_the_title( $post->post_parent );
// Append to the image caption field:
if( false == stripos( $data['post_excerpt'], $append ) ) {
$data['post_excerpt'] .= $append;
}
// Append to the image description field:
if( false == stripos( $data['post_content'], $append ) ) {
$data['post_content'] .= $append;
}
return $data;
}
但它不起作用。任何想法为什么?
【问题讨论】: