Last active
February 6, 2017 02:19
-
-
Save rgadon107/fc310c67e56c4140a3a1ce3591ae720f to your computer and use it in GitHub Desktop.
Archive template file for the Tours custom post type.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Archive template file for the Tours custom post type | |
* | |
* @package spiralWebDB\GenesisDeveloper | |
* | |
* @since 1.0.2 | |
* | |
* @author Robert A. Gadon | |
* | |
* @link http://spiralwebdb.com | |
* | |
* @license GNU General Public License 2.0+ | |
*/ | |
namespace spiralWebDB\GenesisDeveloper; | |
add_action( 'pre_get_posts', __NAMESPACE__ .'\modify_query_vars_if_archive' ); | |
/** | |
* Modify the default Query Vars for the custom post type. | |
* | |
* @since 1.0.2 | |
* | |
* @param array $query_vars Array of query variables to modify for the custom post type. | |
* | |
* @return array $query_vars | |
*/ | |
function modify_query_vars_if_archive( $query_vars = array() ) { | |
if( is_post_type_archive( $post_type = 'tours' ) ) { | |
$query_vars = array( | |
'post_type' => 'tours', | |
'order' => 'ASC', | |
'orderby' => 'menu_order', | |
); | |
foreach ( $query_vars as $var => $value ) { | |
set_query_var( $var, $value ); | |
} | |
} | |
return $query_vars; | |
} |
Make sure to add the file path name to the child theme's autoload.php
file so it gets preloaded before initializing the Genesis framework (parent theme). Then the preregistered callback will get registered and the callback will fire.
No need to include genesis();
at the end of the file if preloading the archive template in the child theme. Once the template file is preloaded, initialize Genesis and the template will run when called.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Conditional
is_post_type_archive()
returns true onarchive-tours.php
page.$query_vars
returns the array values assigned above after looping through the array usingforeach
.An inspection of the
global $wp_query
variable after the array loop indicates that the$query_vars
were properly modified.However, the 'Simply Show Hooks' plugin tells me that the callback above is not preregistered to the
pre_get_posts
event. I'm stumped as to why.