Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see if a post exists based on a meta value

Tags:

php

wordpress

Is there any way to see if a post exists by a meta value?

For instance, lets say I want to see if another post has a unique meta value of "pictureID", and if so do something else.

Is there a way I could write that clause in php?

Thank you

like image 396
OSK Avatar asked Jan 29 '26 21:01

OSK


1 Answers

if you dont know the post id then

you can use custom wordpress query to check post meta according to key like

global $wpdb;
$wpdb->get_results( "select * from $wpdb->postmeta where meta_key = 'pictureID' " );

And then you can get all results with post id and then get that post data.

Hope this helps ;)

like image 58
ashu joshi Avatar answered Feb 01 '26 11:02

ashu joshi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!