Skip Navigation

[Resolved] show only primary taxonomy in a view

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 9 replies, has 2 voices.

Last updated by nicolaT-2 1 year, 5 months ago.

Assisted by: Minesh.

Author
Posts
#2519685

Hi, is it possible to create a view that prints only the taxonomy elements that are marked as primary? How can we do this?

Thanks,
Nicola

#2520131

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I would like to know first how the taxonomy marked as primary - are you using any addon plugin for that? Where you mark term as primary term?

Can you please share all those required information, maybe screenshot would help as well.

#2520163
toolset-primary-taxonomy.png

Hi Minesh,
the taxonomy is marked as primary using standard WordPress function. For example, in the uploaded image you can see the "Branches" taxonomy used to classify doctors. The doctor of this screenshot works in the ambulatories "allergology" and "dermatology", so i need to select both taxonomies to correctly show his activity. Anyway, although he works in both ambulatories, the main one for him is "dermatology", so I also have to be able to extract only this one in a view that should print a text like "Doctor [name], head of [primary branch].

I hope I made clear why I need to extract only the primary taxonomy.

Cheers,
Nicola

#2520199

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

It seems the primary term feature is coming from Yoast SEO.

Can you please share problem URL of one of the post where you want to display "Doctor [name], head of [primary branch]" as well as admin access details.

*** Please make a FULL BACKUP of your database and website.***

I would also eventually need to request temporary access (WP-Admin) to your site. I have set the next reply to private which means only you and I have access to it.

#2520313

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I could not able to access the plugins page. Can you please grant me access to plugins page as I would like to check in database how the primary category is stored.

#2520361

Hi Minesh, sorry for the trouble, now you should be ok.

Nicola

#2520363

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

You did not grant permission to add/remove plugins. Can you please do that. I require to install the plugin to access the database.

#2520373

The project is a multisite network, to manage plugins you need to go here hidden link

#2520415

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now: hidden link

I've added the following code to "Custom Code" section offered by Toolset with code snippet "toolset-custom-code":
=> hidden link

add_filter('wpv_filter_query', 'func_filter_by_yoast_primary_term', 99, 3);
function func_filter_by_yoast_primary_term( $query_args, $view_settings, $view_id ) {
    global $post;
    if($view_id == 2112 ){
      
      $query_args['tax_query'][0]['terms'] = 0;
      $primary_term = get_post_meta($post->ID,'_yoast_wpseo_primary_branca-tax',true);
      if(!empty($primary_term)) {
        
     	 $query_args['tax_query'][0]['terms'] = $primary_term;
     }
       
   
     }
    return $query_args;
}
#2520437

That's great Minesh! It's working! Thank you very much, I would not have been able to solve it by myself.

Cheers,
Nicola

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.