Get term slug by term id and then explode it

I guess the problem is here. $slug = $term->slug; $explodedSlug = explode(‘-‘, $_slug); you are passing an undefined array $_slug to explode function. the correct array is $slug. so your complete code should be something like below. function revised_featured_courses_query() { $meta_query = WC()->query->get_meta_query(); $tax_query = WC()->query->get_tax_query(); $tax_query[] = array( ‘taxonomy’ => ‘product_visibility’, ‘field’ => ‘name’, … Read more

Query and display only by first letter of the get_field value

Hope the below code block will help you. Please read the comments carefully. The code block- // Your previous code. // Say this is your $oder_terms variable $order_terms = array( ‘Sanchez’ => ‘Sanchez Link’, ‘Smith’ => ‘Smith Link’, ‘Dramatist’ => ‘Dramatist Link’, ‘Rashed’ => ‘Rashed Link’, ‘Munez’ => ‘Munez Link’, ‘James’ => ‘James Link’, ‘Jacky’ … Read more

Display posts belonging to child term

I was able to get this working with the following code. I used the relation operator AND, referenced the var ($this_term) that contained get_queried_object(); to set the taxonomy in the tax_query and adjusted the term field in the tax_query. $this_term = get_queried_object(); $args = array( ‘parent’ => $this_term->term_id, ‘orderby’ => ‘slug’, ‘hide_empty’ => false ); … Read more

Assign Specific Template for Custom Post slug

Looking at the template hierarchy it does not look like there is a way to do this automatically, by post type and taxonomy. But, you could use a page template which you would need to select on every custom post where you want to use the different template. In the code where you define the … Read more

Terms change id after importing

Off the top of my head, you’d have to either: (a) bypass the import functionality in WP and do it direct to the database, so the term IDs stay the same (i.e. export/import from phpMySQL). or (b) write a “run once” data migration function to update your term IDs once they’re imported, using a reference … Read more

Order get_terms by multiple meta_values

That is because get_terms() does not accept array type as a value for the ‘orderby’ parameter. The documentation says about this parameter: ‘orderby’ (string) Field(s) to order terms by. Accepts term fields (‘name’, ‘slug’, ‘term_group’, ‘term_id’, ‘id’, ‘description’), ‘count’ for term taxonomy count, ‘include’ to match the ‘order’ of the $include param, ‘meta_value’, ‘meta_value_num’, the … Read more

Grabbing taxonomy terms and inserting them into an array

This creates the multidimensional array in advance and then assigns it to options. The multidimensional array is created by assigning an array to each element of the main array. I have reused the $feat_pages_terms variable, but you can also create a separate variable using array() and assign array elements to that, I am including those … Read more

Count the number of a post types associated with another post type

Sounds like you need to use WP_Query or something similar. <?php // First query: get all destinations $args = array( ‘post_type’ => ‘destination’, ‘posts_per_page’ => -1, ‘no_found_rows’ => ‘true’ // skips pagination ); $destinations = new WP_Query($args); // Now for every destination: foreach($destinations as $destination) { // Second query to get tours $secondargs = array( … Read more