Last active
January 31, 2020 19:59
-
-
Save ianhoyte/0223b5e0e9dae2c16fd1a1197f696ac0 to your computer and use it in GitHub Desktop.
Rewrite the WP-Shopify (https://wpshop.io/) post types to retain their permalink structure if a custom post type structure is set.
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
<?php | |
/** | |
* wps_rewrite_post_type_args | |
* | |
* Retains the permalink structure if a custom permalink structure is | |
* set within Wordpress. | |
* | |
* @param array $args Wordpress post type arguments. | |
* @param string $post_type The post type's slug. | |
* @param array $settings The plugin settings data pulled in from the DB. | |
* @return array $args Modified wordpress arguments. | |
*/ | |
function wps_rewrite_post_type_args( $args, $post_type ) { | |
global $wpdb; | |
$slug = false; | |
// retrieve the plugin URL settings | |
$settings = $wpdb->get_results( "SELECT `url_products`, `url_collections` FROM wp_wps_settings_general" ); | |
if ($post_type == 'wps_products') { | |
$slug = $settings[0]->url_products; | |
} else if ($post_type == 'wps_collections') { | |
$slug = $settings[0]->url_collections; | |
} else if ($post_type == 'wps_orders') { | |
$slug = 'orders'; | |
} | |
if ($slug) { | |
$args['rewrite'] = array( | |
'slug' => $slug, | |
'with_front' => false | |
); | |
} | |
return $args; | |
} | |
add_filter( 'register_post_type_args', 'wps_rewrite_post_type_args', 20, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment