While researching for this I came across Categories and products in random order which had a similar but different issue but was able to derive the required information to cut the array.
I modified his $categories = array_slice( $categories, 0, 5 );
to suit my needs. Final answer was just to add an array_slice based on $cat_number
so I modified $all_categories and called it just $categories (as I will later reference $all_categories) and changed the code to following
$categories = get_categories( $args );
$_totals = count($categories);
shuffle($categories);
$all_categories = array_slice( $categories, 0, $number_cats );
Related Posts:
- retrieve thumbnail from post ID of best selling product in category
- Woocommerce – remove product from category
- combine Code 1 with Code 2
- get current product name in functions.php
- Issue adding sub category programmatically
- Pass Category Name, Description and Photo into variables to pass to jQuery
- get taxonomy thumbnail and use it as a variable in code
- Only show size attributes in product box woocommerce when available
- WooCommerce: Display product categories to make IF statement
- Display Sibling WooCommerce Product Categories on Archive Page
- Woocommerce. Get a list of products in the current category on the archive page and product page
- Add Custom Category Description When Empty
- Add a product category to a specific product via a button
- Child-Theme Category View with modified permalinks (%category% removed)
- Need Quick Help With Product Category Page
- WordPress using get_term to retreive slug not working as expected
- How to remove image on single product and get product to span page?
- Product Category Page in Full Width
- Hide child of parent categories already hidden with “get_terms_args” – Woocommerce
- How to correctly add Javascript in functions.php
- Looking to exclude blog posts from category Previous/Next buttons
- Woocommerce: How to override core functions in functions.php?
- Get WooCommerce shipping methods programmatically
- Add a custom text field to WooCommerce admin product data “Variations”
- Translating add to cart woocommerce button [closed]
- How to exclude specific category from the get_the_category(); array
- Help with some php math in WordPress
- How do I display a user’s previous orders as a select box option on a product?
- Automated Cart Update With Alert Box Each Time
- Two Different Links for Same Product – WooCommerce [closed]
- WooCommerce/WordPress: how hide entire table form after submit (Admin Dashboard)?
- Show prices with tax in Woocommerce Mini Cart [closed]
- Problem with custom plugin using AJAX to pull info from php file
- Woocommerce related product text
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- How to make products with no cost in WooCommerce
- get_template_part based upon post’s category
- Different post styles depending on category
- two columns of posts on homepage, one of them “favorites”
- Define specific category name in PHP
- Include Parent Term in wp_list_categories
- I’m trying to create an array with a foreach loop, but the array only stores the last item [closed]
- Add product to cart for user – WC()->cart->add_to_cart [closed]
- What’s a good way to allow overwriting files within a child theme if I want the same folder structure?
- WordPress filter load_textdomain_mofile not working inside a child theme’s functions.php but works form inside a plugin
- Seo Friendly Filter URLs
- how can i add class or span tag at sprintf?
- Display attribute on shop page after the title
- Include style.css in the Child Theme with PHP
- WooCommerce – Moving Product Price to the Left of Add to Cart Button [closed]
- How to hide posts of a specific custom category in WordPress?
- Add new post in existing categories using wp_insert_post
- How to change logo by category
- WordPress WP_Query without query GET parameters
- Where to copy woocommerce files to in my custom theme to avoid editing the core plugin?
- Output category list inside array
- Have Woocommerce show product price if id, when not logged in
- Problems clearing cache
- Define category ID using get_post_meta
- How To Pass Array To get_the_category_by_ID() and Get An Array Back?
- Trying to change featured image from 180×180 to full width on home page
- I need to display posts in subcategory beside posts in main category
- Order category posts by last word of custom field
- Get nice name of category from slug (remove dashes of category)
- How to add a shortcode which runs a .php file for the current post
- Run a sql (update) after 12 hours after the user login. Woocommerce users
- File from parent theme imported to child theme doesn’t work – any ideas?
- How can I change the background color of divs dynamically (depending on an order-status in woocommerce)?
- Use Search Term in html link and redirect
- PHP “warning include_once(): Failed to open stream” Simple HTML DOM in WordPress Child Theme
- How to get content on a blank basket/cart page in a custom theme with woocommerce
- WooCommerce REST API AJAX Auth – 401 response
- Looping through and combining calls to Woocommerce REST API
- How to import woocommerce custom fields data into another site?
- AJAX numerical pagination problem in TwentyFifteen-child theme
- Woocommerce – if selected attribute term equals
- split 1 cart item into instock and back ordered
- Adding a widget under an ‘Add to Cart’ button through a PHP snippet
- Woocommerce Related Product by 2 taxonomy
- Add custom ID attribute to all woocommerce products on archive pages
- Custom content using in_category
- How to properly create multiple conditions to redirect users roles to different pages
- How can i put php code on the wordpress page?
- PHP drop down menu for my get_category child of
- How do I prevent a folder from reappearing in my home directory?
- jQuery doesn’t work in my php snippet
- Rearrange get_categories array compared to another array
- Query seems to be duplicated
- Remove the_content From Loop
- How to add custom checkout field in user details mail template
- Add specific phrase after every product title including the discounted price? [closed]
- Display Sale Price Before Regular Price (WooCommerce)
- WooCommerce – Show ‘Sales’ badge on variable products where only some variations have sales price [closed]
- How to create a container in php then customise it in CSS
- Show button in header when product custom field is not empty
- WordPress 6.1.1 UTF8 Slug Limit Increase
- How to change shipping method title based on cart amount?
- How to add SKU and remove product title from WooCommerce url?
- Product Search in search.php
- using custom pages for myaccount in woocommerce