WordPress替换关键字内容wito自定义帖子标题和链接

时间:2018-06-19 20:11:39

标签: php wordpress

为什么,我尝试在the_content单词中搜索“ PLAYMINOL”并替换为“ LINK”,“ PLAYMONOL”是自定义帖子查询的标题,“ LINK”是“ PLAYMONOL POST”的链接,为此,我尝试创建我主题中的功能如下:

function replace_content($content)
{
$args=array(
    'post_type' => 'produse',   
    'posts_per_page' => -1
);
$my_query = new WP_Query($args);
$search = array();
$link = array();
foreach ($my_query->posts as $p) {
  $search[]= apply_filters('the_title',$p->post_title);
  $link[]= get_post_permalink();
}
$cautare = $search;
$inlocuire = $link;

$content = str_replace($cautare, $inlocuire, $content);
return $content;    
}
add_filter('the_content','replace_content');

但不起作用,怎么了?

0 个答案:

没有答案