【问题标题】:url_to_postid doesn't work with the correct urlurl_to_postid 不适用于正确的 url
【发布时间】:2017-01-16 12:02:33
【问题描述】:

我必须在我的 Wordpress 网站中提取产品的 post_id。 我使用了以下代码:

$actual_link = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";

        $actual_link = substr($actual_link, 0, -19);
        //var_dump($actual_link);
        $post_id = url_to_postid( $actual_link );
var_dump($post_id);

$actual_link 值如下:

http://www.pecso.it/prodotto/741drinkflex-piatto-nondiv/

$post_id 值为 NULL。为什么?你能帮我吗?

【问题讨论】:

  • 移除 $actual_link = substr($actual_link, 0, -19);并检查它是否有效。
  • 谢谢,但我需要使用 $actual_link url 发布..
  • 你为什么在$actual_linksubstr()
  • 因为 $actual_link 包含不属于产品页面永久链接的部分

标签: php wordpress http-post


【解决方案1】:

当前帖子 id 值存储在全局变量中。请查看官方文档的link

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-03
    • 2018-02-11
    • 2016-08-23
    • 1970-01-01
    • 2016-04-02
    • 2023-03-03
    • 1970-01-01
    相关资源
    最近更新 更多