Query Posts With Value From Shortcode?
-
I’m using a plugin called WP-Geolocation-JS which gets geolocation details from a site visitor and allows you display that information using shortcodes, very straightforward.
I am using that data to auto detect the site visitor’s location and filter search results (this is for a business directory website) automatically based on that city. This is to keep someone in Virginia who is searching for a business having to sift through businesses in California.
Now on to the question:
I am trying to query by city, which I am getting from this plugin, and checking it against my custom meta key for city that my posts have.
In short it should work something like this:
$geocity = do_shortcode(‘[mmjs-city]‘);
query_posts(“meta_key=city&meta_value=$geocity&post_type=listings”);But this doesn’t work. I know the short code is working, I can echo that out separately so that’s not the issue. I also know my query posts is working because just to test I manually set $geocity = to my city (the exact same as it displays when I echo out the shortcode for the plugin) and it works just fine.
So the issue, I think atleast, is that the query doesn’t accept a value that outputs from a shortcode?
It’s just baffling to me because I can say “echo do_shortcode(‘[mmjs-city]‘);” and get a value, for example, “Atlanta” and then set $geocity = “Atlanta” and (let’s assume I’m in Atlanta) when I query my posts for that it works. But when I try setting $geocity = do_shortcode(‘[mmjs-city]‘); (which I just proved that the short code has a value of “Atlanta”) and I query my posts it doesn’t work.
Is there a way to get this to work? Is there another way to do what I am trying to do.
I would really appreciate any help anyone has to offer. Thank you!
The topic ‘Query Posts With Value From Shortcode?’ is closed to new replies.