wpsl_store_category_args

  1. Description
  2. Parameters
  3. Usage
  4. Changelog
  5. Source File
  6. Related

Description

This filter allows you to modify the arguments that are used to register the store categories (wpsl_store_category) for the wpsl_stores post type.

The permalink options are set on Store Locator > Settings > Local Pages (Local Pages settings). “Create landing pages?” makes the category pages public, and “Category slug” sets the category part of the URL. You don’t need this filter for those.

To change the names used for the categories in the admin, like “Store Categories”, use the wpsl_store_category_labels filter. It receives the labels array before it’s added to these arguments.

Don’t set show_in_rest to false. The Store Locator and Map blocks load the categories through the WordPress REST API, and the block editor needs it to show the Store Categories panel on the store edit screen.

Parameters

$args - (array) The taxonomy arguments. The defaults are:

KeyDefault
labelsThe labels from the wpsl_store_category_labels filter.
publictrue when "Create landing pages?" is enabled, otherwise false.
hierarchicaltrue
show_uitrue
show_admin_columntrue
update_count_callback'_update_post_term_count'
query_vartrue
rewritearray( 'slug' => 'store-category' ) with the "Category slug" setting. It also has 'with_front' => false when "Remove the front base from the permalink structure?" is enabled. false when "Create landing pages?" is disabled.
show_in_resttrue

Usage

This example hides the category column from the store list on the “All Stores” page:

add_filter( 'wpsl_store_category_args', 'custom_store_category_args' );
function custom_store_category_args( $args ) {
// Hide the category column on the All Stores page.
$args['show_admin_column'] = false;
return $args;
}

Add the filter directly in your functions.php file or plugin, not inside a function that runs on the init hook. WP Store Locator registers the store categories twice on each page load, on init priority 0 and 10, so your filter has to be in place before init starts.

After you add or change code that changes the rewrite argument, go to Settings > Permalinks and click “Save Changes”. Until you do, WordPress doesn’t know the new URLs.

Changelog

VersionDescription
3.0Moved to includes/core/post-types/class-register.php. show_in_rest is now always true; in 2.x it was only true on WordPress 5.0 and later. The filter now runs twice on each page load.
2.0Introduced.

Source File

This filter is located in /includes/core/post-types/class-register.php.

Placement

The code needs to be placed in the functions.php file inside your active theme folder.