wordpress: How to Get post title for given url?

2019-09-04 03:20发布

I have a separate wordpress table where there is only post url in that.

Now, I want post title from that url.

Tried <?php $postid = url_to_postid( $url ); ?> Doesn't seem to be working good. Returns 0 to some of the urls.

Any ideas/suggestions ?

标签: php wordpress
1条回答
仙女界的扛把子
2楼-- · 2019-09-04 03:48

Try the following query:

$post_title=$wpdb->get_var("SELECT post_title FROM $wpdb->posts WHERE guid='$url'");

Or

post_url is a column name

$tbl_new='table name where post urls are stored';
$post_title=$wpdb->get_var("SELECT post_title FROM $wpdb->posts a  JOIN $tbl_new b on a.guid=b.post_url WHERE guid='$url'");
查看更多
登录 后发表回答