我制作了以下php程序,以通过某些自定义元值设置(覆盖)帖子标记。我将其设置为header.php时,程序本身运行良好。
<?php if ( is_single() ) : ?>
<?php
global $post;
$post_id = $post->ID;
$tags[] = get_post_meta( $post->ID, 'aaaaa', true );
$tags[] = get_post_meta( $post->ID, 'bbbbb', true );
$tags[] = get_post_meta( $post->ID, 'ccccc', true );
$tags[] = get_post_meta( $post->ID, 'ddddd', true );
$tags = array_unique( array_filter( $tags ) );
get_post_meta results
wp_set_post_tags($post_id , $tags, false );
?>
<?php endif; ?>
现在,我发现我的程序在通过浏览器打开文章(帖子)之前不会影响标签。我有很多帖子,我希望通过程序更改标签。有没有办法通过帖子运行我的程序而不用浏览器打开?
这是我尝试过的其他代码。我像上面的代码一样在header.php上设置了此代码。它像上面的代码一样工作。我仍然需要打开很多职位。有没有办法在后台的所有帖子中运行程序?
<?php if (is_singular('post')): ?>
<?php
global $post;
$post_id = $post->ID;
$tags[] = get_post_meta( $post->ID, 'aaaaa', true );
$tags[] = get_post_meta( $post->ID, 'bbbbb', true );
$tags[] = get_post_meta( $post->ID, 'ccccc', true );
$tags[] = get_post_meta( $post->ID, 'ddddd', true );
$tags = array_unique( array_filter( $tags ) );
get_post_meta results
wp_set_post_tags($post_id , $tags, false );
?>
<?php endif; ?>
希望对您有帮助。
$args = array(
'post_type' => 'post'
);
$post_query = new WP_Query($args);
if($post_query->have_posts() ) {
while($post_query->have_posts() ) {
$post_query->the_post();
$post_id = get_the_ID();
$tags[] = get_post_meta( $post->ID, 'aaaaa', true );
$tags[] = get_post_meta( $post->ID, 'bbbbb', true );
$tags[] = get_post_meta( $post->ID, 'ccccc', true );
$tags[] = get_post_meta( $post->ID, 'ddddd', true );
$tags = array_unique( array_filter( $tags ) );
get_post_meta results
wp_set_post_tags($post_id , $tags, false );
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句