[wp-trac] [WordPress Trac] #41708: tax_query not (instantly) available from functions.php
WordPress Trac
noreply at wordpress.org
Tue Aug 22 21:40:19 UTC 2017
#41708: tax_query not (instantly) available from functions.php
----------------------------+-----------------------------
Reporter: Digital Noises | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 4.8.1
Severity: normal | Keywords:
Focuses: performance |
----------------------------+-----------------------------
I created a tax_query of a custom post type from within a file that I
'''referenced in functions.php'''
I figured out that I could query all of my custom posts by using: (so I
had my positive)
{{{#!php
<?php
$args = array('post_type' => 'mycpt');
}}}
I assumed it should be easy to specify my quey with a tax_query
{{{#!php
<?php
'tax_query' => array(
array(
'taxonomy' => "mytax",
'field'=>'slug',
'terms'=> array('mytaxterm')
)
)
}}}
Unfortunately this '''returns no result at all from within functions BUT
from within i.e. header.php'''
My workaround to retrieve all needed values from all those posts was -
calling it via a hook from within functions.php
(might be a dumb way?!)
I added:
{{{#!php
<?php
add_action( 'wp_head','doMyTaxQuery' );
}}}
And did all I needed to do inside the function »doMyTaxQuery«.
**********
PS: I figured that I could not use »get_terms« from my query inside
functions.php either.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41708>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list