[wp-hackers] get wp_query object when you have url to post

Nikola Nikolov nikolov.tmw at gmail.com
Fri Mar 21 13:51:36 UTC 2014


Actually WordPress does the same thing internally(well it's a bit more
complicated, but it's about the same) - it goes through all rewrite rules
until it finds a matching regex pattern.

You might be able to run the method that generates the query, but I don't
know if it won't have a performance hit(especially if you'll be running it
for multiple links).

What is the reason behind why you need this functionality?

Nikola


On Fri, Mar 21, 2014 at 2:02 PM, Konrad Karpieszuk <kkarpieszuk at gmail.com>wrote:

> hi
>
> Imagine that you have some text (let it be a post content) with urls. I
> want to take all urls (it is something what i know how to do), check if the
> links are local (again, something easy) and if they are, check what exactly
> should be queried from wordpress, what should be in wp_query.
>
> Does wordpress has some easy function/methid to do this?
>
> Like get_wp_query_by_url('http://example.com/archive/some-category-name')
> which will return wp_query for 'some-category-name' archive page.
>
> Another question, maybe more suitable for me: does wordpress has some easy
> function/method which will return $_GET params which should be set when we
> want to open this url?
>
> Something like get_query_params_by_url('http://example.com/some-post');
> which will return:
>
> array(
> 'p' => 12
> )
>
> (params which normally will be added as $_GET to url if permalinks are set
> to default)
>
> Thank you in advance. Now everything what i do is to get url, slice it to
> get its path and compare it with wp_rewrite. But because wordpress somehow
> knows what it must display if somebody type some url in address bar i am
> little affraid that there is some easier method than manual checking if url
> matches to wp_rewrite rules
>
> --
> (en) regards / (pl) pozdrawiam
> Konrad Karpieszuk
> http://tradematik.pl wtyczka do WordPressa do tworzenia sklepów dla
> klientów z Polski
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list