Trouble using get_pages with pre_get_posts hook
-
Hi there,
I’m struggling to get the results I want here. After a couple hours of googling/forum scraping, I’ve decided it’s time for a new post.I’m trying to look at children of the current (queried) page, and if the page has a specific term within a specific taxonomy, show the child page content instead of the originally queried page. Here’s my code (via gist).
This method actually works perfectly on the home page. The child page of “Home” is found, and the query is altered to show that page. However, I get no results when I try this on /about-us/mission/ for example (even though there is a child page that fits the conditions). If I
var_dump($children)
, on the “Home” page, I get one result: the correct one. If Ivar_dump($children)
on another page, I just get an array of ALL top level pages (and no children of anything). What am I doing wrong here? I’ve tried this without the ‘parent’ parameter AND without the ‘child_of’ parameter.If I
var_dump($pid)
on any page besides the home page, I receive “int(0)”. I imagine this is the root of the problem. Something about$query->query_vars['page_id']
is not yielding the actual ID of the current page. I don’t know if just haven’t found the correct combination of parameters, or if there is a fundamental flaw in what I’m attempting…Any help would be much appreciated.
- The topic ‘Trouble using get_pages with pre_get_posts hook’ is closed to new replies.