search – Shared Facet between Taxonomy and Content Field

My search page needs to show results from both content types and taxonomies.

Both the content type and taxonomies that I am searching on have a field called training_location. The training_location field is also a taxonomy with only two options: “Remote” and “In-Person”.

Is there a way to merge a facet so that I can filter results for both a content type and taxonomy that has the training_location field?

To be clear, the system is currently forcing me to create a separate facet for the content type training_location field and a separate facet for the taxonomy training_location field, which is not what I want.

Automatically add entries per category custom taxonomy upon plugin installation

I have a plugin created with boilerplate from this site:
https://wppb.me/

And I would like to understand how to automatically add 4 entries in the custom taxonomy category that I have already processed.

I guess this code goes on the activator.php file, but I don’t know what code to apply to automatically generate these 4 categories.

Can you guys help me?

Custom Taxonomy template is not recognised

I have created a custom post type (products), and at the moment I have 2 custom taxonomies (lips and eyes).

I can get the archive to show up for ‘products’, and I can get to the URL for the archive for the categories under ‘lips’, but I cannot get the archive to show for the taxonomies.

I have been through every question I can find, and I have checked the answers against what I have done, but for the life of me I can’t figure out what is going wrong.

I have a taxonomy template, ‘taxonomy-lips.php’, but it just keeps defaulting back to my front-page.php template.

Here is my code for the post type:

function my_first_post_type() {

$args = array(
    
    'labels' => array(
        
        'name' => 'Products',
        'singular_name' => 'Product',
        
        ),
        
    'hierarchical' => true,
    'public' => true,
    'has_archive' => true,
    'menu_icon' => 'dashicons-list-view',
    'supports' => array('title', 'editor', 'thumbnail'),
    'rewrite' => array('slug' => 'shop-products'),
    'taxonomies' => array('lips', 'eyes'),
    
    ); }
    register_post_type('products', $args);

    add_action('init', 'my_first_post_type');

And here is the code for my taxonomy:

    function my_first_taxonomy()
    {
    $args = array(
    
    'labels' => array(
        
        'name' => 'Lips',
        'singular_name' => 'Lips',
        ),
        
    'public' => true, 
    'hierarchical' => true,
    'rewrite' => array('slug' => 'lips'),
   
    
    );
    
    register_taxonomy('lips', array('products'), $args);

    }
    add_action('init', 'my_first_taxonomy');

I have reset the permalinks many times, and nothing changes.

Sorry, I know this question has been asked many times, I just can’t figure out what I have done! I’m very new to all of this, so be gentle lol, I might not understand anything too complex!

7 – Views contextual display based on taxonomy for no value

I have a content type that has a name field and a taxonomy field that contains cities. I want the view to display by default the city as title and the message “nobody lives in city X” for each of the cities, i.e. “Nobody lives in New York” before I create any content. Once I create a person and select New York, it should display “John lives in New York”. I assume this involves contextual filters and maybe relationship with the taxonomy entity, but I couldn’t make it work.

Any help?

D7 Views contextual display based on taxonomy for no value

I have a content type that has a name field and a taxonomy field that contains cities. I want the view to display by default the city as title and the message “nobody lives in city X” for each of the cities, i.e. “Nobody lives in New York” before I create any content. Once I create a person and select New York, it should display “John lives in New York”. I assume this involves contextual filters and maybe relationship with the taxonomy entity, but I couldn’t make it work. Your help is greatly appreciated.

rewrite tag – How to build a achieve page for a custom CPT with multiple taxonomy button filter

This is an extended question from
Permalink for CPT with taxonomy


I am building a website that has a custom CPT and a few custom taxonomies.
The goal is to setup the archive page to have a front-end filter with buttons.

I have struggling with a few different questions…hoping someone can help.

Here is a screenshot of the HTML mark for the achieve page:

filter html markup screenshot

Here’s the current setup:

Custom Post Type:
English Speaking, with slug name “english-speakings”

Custom Taxonomies:
(1) Question Tasks (“english_speaking_tasks”), and its terms: “task1”, “task2”, “task3”

(2) Difficulties (“english_speaking_difficulties”) and its terms: “easy”, “advanced”, “pro”

(3) Course (“english_speaking_courses”) and its terms: “course-a”, “course-b”, “course-c”

Custom CPT: English-Speakings

register_post_type( 'english-speakings', array(
    'label' => 'English Speaking',
    'public' => true,
    'rewrite' => array(
        'slug' => 'english/speaking/%speaking_task%/%course%/',
    ),
    // Other args here.
) );

Taxonomy

// Task
register_taxonomy( 'speaking-task', array( 'english-speaking' ), array(
    'label' => 'Speaking Tasks',
    'public' => true,
    'rewrite' => array(
        'slug' => 'english/speakings',
    ),
    // Other args here.
) );


// Difficulties 
register_taxonomy( 'english_speaking_difficulties', array( 'english-speaking' ), array(
    'label' => 'Speaking Tasks',
    'public' => true,
    'rewrite' => array(
        'slug' => 'english/speaking/difficulties',
    ),
    // Other args here.
) );



// Course
register_taxonomy( 'english_speaking_courses', array( 'english-speaking' ), array(
    'label' => 'Speaking Tasks',
    'public' => true,
    'rewrite' => array(
        'slug' => 'english/speaking/courses',
    ),
    // Other args here.
) );

'slug' => 'english/speaking/%speaking_task%/???????/',

**Question: For the URL format, I need some guidance or suggestion here… **

For SEO purpose, I like to setup a Clean URL, but I do not need all the taxonomy names to show up there, and I might have more taxonomies created in the future…

Instead of https://example.com/{cpt-slug}/{task-slug}/{course-slug}/{difficulty-slug}
( https://example.com/english/task1/course-a/pro )

The ideal format is:

Example: https://example.com/english/task1/2035 or 20-35 or 20/35
( where 20 and 35 are the term id: course-a(“20”), pro(“35”))


Register the custom var with WP.

I have three taxonomy that need to be functional as filters, so I am going to register them to WP as custom vars:

function cpt_english_register_query_vars( $vars ) {
    $vars() = 'course';
    $vars() = 'task';
    $vars() = 'difficulty';
    return $vars;
}
add_filter( 'query_vars', 'cpt_english_register_query_vars' );

Build Query for the CPT Achieve page

    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; //use 'page' if the query is on a static front page
    
    
    $course =  get_query_var( 'course' ) ?: "courseA"; //set default value as "courseA"
    $task = get_query_var('task') ?: "task1"; // default value "task1" 
    $difficulty = get_query_var('difficulty') ?: "easy"; //default value "easy"
    
    $args = array( 
        'post_type' => 'english_speakings',
        'post_status'    => 'publish',
        'posts_per_page' =>  20 ,
        'paged' => $paged,
    
         'tax_query' => array(
    
           'relation' => 'AND', 
            
            array(
                'taxonomy' => 'english_speaking_tasks',
                'field'    => 'slug',
                'terms'    => $task,
            ),
    
            array(
                'taxonomy' => 'english_speaking_course',
                'field'    => 'slug',
                'terms'    => $course,
            ),
    
            array(
                'taxonomy' => 'english_speaking_difficlties',
                'field'    => 'slug',
                'terms'    => $difficulty,
            ),
    
        ),
    );

$the_query = new WP_Query( $args );

And Output the custom Query:

<?php

if ( $the_query->have_posts() ) {

    while ( $the_query->have_posts() ) {

        $the_query->the_post();
?>

Content ...

<?php
    }
    wp_reset_postdata(); //wp_reset_query();
} else {
    echo '<div class="card-body"><p>Sorry, there are no posts to display</p></div>';
}
?>

And I am lost….

The following are the parts I have trouble with:

(1) I have trouble making up my mind about the URL structure, need advise here

(2) “Adding Rewrite Tags”.. I do not understand how to use rewrite tags, regex and match1, match(2) ..these are very confusing to me

(3) For the front-end the taxonomy term buttons, I am not sure how to build the for each filter term buttons.

(4) I am not sure how to linked the custom var with the correct taxonomy term

custom taxonomy – update attribute of specific products in woocommerce

I need to change the value of all product attributes that have a specific attribute with a specific value.
for example, I have 10 phones with Ram(attribute): 64 GiB (attribute value) and 5 Phone with Ram(attribute): 64 GB (attribute value).
I need to change all products with Ram: 64 GiB to Ram: 64 GB, So there will be no 64GiB anymore, I tried the below code and https://stackoverflow.com/a/65690805/6934036. but they didn’t work

$product_id = 14352; //some product id
$storage = get_the_terms($product_id, 'pa_internal-storage');
$newStorage = '64GB';
update_post_meta($product_id, 'pa_internal-storage', $newStorage);

custom taxonomy – Add some html code in my wordpress theme template


Your privacy


By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.




Cannot view taxonomy terms for one vocabulary

I’m running core 8.9.16 (and have run database updates) and have 24 vocabularies. One is giving me an error when I try to list terms, the others are fine. This seems to have happened when I updated to 8.9.1. But when using the contrib taxonomy manager module, I can list the terms. I don’t know if this is a core issue, or perhaps corrupted data in the table. I’d appreciate any tips on how to solve this. Here’s the error screen:

Error: Call to a member function id() on null in DrupaltaxonomyTermStorage->loadTree() (line 276 of core/modules/taxonomy/src/TermStorage.php).

DrupaltaxonomyTermStorage->loadTree('team_member_types', 0, 1, 1) (Line: 177)
DrupaltaxonomyFormOverviewTerms->buildForm(Array, Object, Object)
call_user_func_array(Array, Array) (Line: 532)
DrupalCoreFormFormBuilder->retrieveForm('taxonomy_overview_terms', Object) (Line: 278)
DrupalCoreFormFormBuilder->buildForm(Object, Object) (Line: 91)
DrupalCoreControllerFormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
DrupalCoreEventSubscriberEarlyRenderingControllerWrapperSubscriber->DrupalCoreEventSubscriber{closure}() (Line: 573)
DrupalCoreRenderRenderer->executeInRenderContext(Object, Object) (Line: 124)
DrupalCoreEventSubscriberEarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
DrupalCoreEventSubscriberEarlyRenderingControllerWrapperSubscriber->DrupalCoreEventSubscriber{closure}() (Line: 151)
SymfonyComponentHttpKernelHttpKernel->handleRaw(Object, 1) (Line: 68)
SymfonyComponentHttpKernelHttpKernel->handle(Object, 1, 1) (Line: 57)
DrupalCoreStackMiddlewareSession->handle(Object, 1, 1) (Line: 47)
DrupalCoreStackMiddlewareKernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupalpage_cacheStackMiddlewarePageCache->pass(Object, 1, 1) (Line: 85)
Drupalpage_cacheStackMiddlewarePageCache->handle(Object, 1, 1) (Line: 47)
DrupalCoreStackMiddlewareReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
DrupalCoreStackMiddlewareNegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
StackStackedHttpKernel->handle(Object, 1, 1) (Line: 708)
DrupalCoreDrupalKernel->handle(Object) (Line: 19)

Here’s what I’ve found running it through debug (in phpStorm); line 276 is

if (isset($this->treeParents($vid)($load_entities ? $term->id() : $term->tid))) {

$load_entities is true
$term is null, though

In line 275, $term is loaded:

$term = $load_entities ? $term_entities($child) : $this->treeTerms($vid)($child);

$child is set to 54, which is a non-existent term. The term was somehow deleted. I don’t recall deleting it. It is set in line 270:

$child = current($this->treeChildren($vid)($parent))

and it is set to 54 at the end of the loop by looking at the next value. The values in $this->treeChildren($vid)($parent) are 53, 54, 67, 72, 68

If this is mangled data, how do I remove the 54?

commerce – Drupal 9 Taxonomy Term view not displaying products

I’ve edited the default product type and added a taxonomy term reference field and added some products that reference my product categories.

The default taxonomy view isn’t display my products, I believe because it just shows related nodes?!

How do I get the taxonomy view to display related products?