在产品永久链接中获取产品作者ID

我正在使用woo Commerce和WC Vendor插件来建立供应商商店。现在, 我还希望woo Commerce产品的永久链接中的产品作者ID, 是否有人知道如何执行此操作。

提前致谢


#1


我通过在functions.php文件中编写一个简单函数找到了解决方案, 对我有用的函数是

add_filter('post_type_link', 'add_author_id', 10, 4);

function add_author_id($post_link, $post, $leavename, $sample) {
if ('product' != get_post_type($post))
    return $post_link;
$authordata = get_userdata($post->post_author);
$author = $authordata->id;
$post_link = str_replace('%author%', $author, $post_link);
return $post_link;
 }

来源:

https://www.srcmini02.com/65119.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_41086.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?