最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】给wordpress插件evernote-sync添加同步帖子的post_name即slug别名

WordPress crifan 2230浏览 0评论

折腾:

【已解决】调试Wordpress插件Evernote sync

期间,在:

【已解决】调试并解决Evernote-sync的wordpress帖子发布时间差8小时的bug

之后,顺带参考:

wp_insert_post() | Function | WordPress Developer Resources

也找到了后续想要去实现的slug的字段是post_name:

<code>  'post_name' =&gt; [ &lt;the name&gt; ] // The name (slug) for your post
</code>

所以后来代码加上:

//追加post_name = slug
if (!empty($note->attributes->sourceURL)){
    $my_post[‘post_name’] = $note->attributes->sourceURL;
}

对于帖子中已经设置了URL的值(为wordpress中post的post_name=slug)

则调试期间可以看到对应的信息:

同步完成后,则wordpress中可以看到帖子中已有post_name=slug=别名了:

【总结】

此处evernote-sync中调试发现可以拿到note对象的各个信息,所以想到了通过印象笔记软件中设置帖子的URL,代码中对应着$note->attributes->sourceURL,代码为:

//追加post_name = slug
if (!empty($note->attributes->sourceURL)){
    $my_post[‘post_name’] = $note->attributes->sourceURL;
}

即可获得对应的帖子的别名的值,然后给wordpress的post的post_name即可实现同步别名的效果。

转载请注明:在路上 » 【已解决】给wordpress插件evernote-sync添加同步帖子的post_name即slug别名

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
90 queries in 0.174 seconds, using 22.11MB memory