Created
May 1, 2024 19:37
-
-
Save SamuelHadsall/177611f36092921e87e5de8547da83af to your computer and use it in GitHub Desktop.
Post type and redirects
This file contains 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
public function uni_custom_rewrite_rules() { | |
// Make sure we can still get to the movers page | |
add_rewrite_rule( | |
'^movers/?$', | |
'index.php?pagename=movers', | |
'top' | |
); | |
add_rewrite_rule( | |
'^movers/([^/]+)/?$', | |
'index.php?post_type=state&state=$matches[1]', | |
'top' | |
); | |
add_permastruct('movers', '/movers/%state%/%msa_state_abbreviation%', array( | |
'with_front' => false, // Whether the structure should be prepended with WP_Rewrite::$front. | |
'ep_mask' => EP_NONE // Endpoint mask defining the template file to use. | |
)); | |
add_rewrite_rule( | |
'^movers/([^/]*)/?([^/]*)?', | |
'index.php?post_type=market&msa_state_abbreviation=$matches[1]&name=$matches[2]', | |
'top' | |
); | |
} | |
public function uni_custom_flush_rewrite_rules() { | |
flush_rewrite_rules(); | |
} | |
public function uni_custom_post_type_template() { | |
// Output query variables for debugging | |
global $wp_query; | |
if (is_singular('market')) { | |
require_once plugin_dir_path( dirname( dirname( __FILE__ ) ) ) . 'public/wp-templates/single-market.php'; | |
exit; | |
} | |
if (is_singular('state')) { | |
require_once plugin_dir_path( dirname( dirname( __FILE__ ) ) ) . 'public/wp-templates/single-state.php'; | |
exit; | |
} | |
} |
This file contains 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
public function uni_market_post_type() { | |
$names = [ | |
'name' => 'market', | |
'singular' => 'Market', | |
'plural' => 'Markets', | |
'slug' => 'market', | |
]; | |
$options = [ | |
'has_archive' => true, | |
'query_var' => true, | |
'publicly_queryable' => true, | |
'hierarchical' => true, | |
'capability_type' => 'page', | |
'show_in_menu' => $this->plugin_name, | |
'show_in_graphql' => true, # Set to false if you want to exclude this type from the GraphQL Schema | |
'graphql_single_name' => 'market', | |
'graphql_plural_name' => 'markets', # If set to the same name as graphql_single_name, the field name will default to `all${graphql_single_name}`, i.e. `allDocument`. | |
'rewrite' => false, | |
'supports' => [ | |
'title', | |
'page-attributes' | |
], | |
'menu_icon' => 'dashicons-store', | |
]; | |
$locations = new PostType( $names, $options ); | |
$locations->register(); | |
} | |
public function uni_state_post_type() { | |
$names = [ | |
'name' => 'state', | |
'singular' => 'State', | |
'plural' => 'States', | |
'slug' => 'state', | |
]; | |
$options = [ | |
'has_archive' => false, | |
'query_var' => true, | |
'publicly_queryable' => true, | |
'hierarchical' => true, | |
'capability_type' => 'page', | |
'show_in_menu' => $this->plugin_name, | |
'show_in_graphql' => true, # Set to false if you want to exclude this type from the GraphQL Schema | |
'graphql_single_name' => 'state', | |
'graphql_plural_name' => 'states', # If set to the same name as graphql_single_name, the field name will default to `all${graphql_single_name}`, i.e. `allDocument`.t | |
'rewrite' => false, | |
'supports' => [ | |
'title', | |
'page-attributes' | |
], | |
'menu_icon' => 'dashicons-location', | |
]; | |
$locations = new PostType( $names, $options ); | |
$locations->register(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment