wordpress: How to Get post title for given url?

2019-09-04 03:12发布

问题:

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 ?

回答1:

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'");


标签: php wordpress