I'm trying to get the post by it's guid.
I tried:
$post = get_post(array('guid' => 'foo'));
But that just returns the first post. (it's guid is not 'foo').
What am I missing?
You can't pass GUID in get_post()
.
I'd recommend you creating a function that returns a post ID from a GUID.
function getIDfromGUID( $guid ){
global $wpdb;
return $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid=%s", $guid ) );
}
var_dump( get_post( getIDfromGUID('http://localhost/wpdev/?p=10') ) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With