【问题标题】:Getting Product author id in products permalinks在产品永久链接中获取产品作者 ID
【发布时间】:2017-12-08 21:12:59
【问题描述】:

我正在使用 woo commerce 和 WC Vendor 插件来创建供应商商店。现在我想要产品作者 ID 以及 woo 商业产品的永久链接中的任何人都知道如何做到这一点。

提前致谢

【问题讨论】:

    标签: wordpress woocommerce wordpress-theming


    【解决方案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;
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多