Skip to content

Instantly share code, notes, and snippets.

@rgadon107
Last active February 6, 2017 02:19
Show Gist options
  • Save rgadon107/fc310c67e56c4140a3a1ce3591ae720f to your computer and use it in GitHub Desktop.
Save rgadon107/fc310c67e56c4140a3a1ce3591ae720f to your computer and use it in GitHub Desktop.
Archive template file for the Tours custom post type.
<?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;
}
@rgadon107
Copy link
Author

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