How can i get only bottom level terms of a taxonomy or category in views?

How can i get only parent terms of a taxonomy ?

This is a very popular question asked in many WordPress forums and Toolset Support and as a result, i am going to write a code snippet.

Lets assume, that the depth of taxonomy hierarchy is 3 and is explained by the following example of countries, provinces and states.

  • Australia ( Parent)
    • Queensland (Child)
      • Brisbane ( Child of a child)

CODE SNIPPED TO FETCH TOP LEVEL OR PARENT TAXONOMY TERM

Copy and paste the below snipped in your current active theme functions.php file. Then replace $location variable to your current taxonomy name and then use the shortcode [ds-parent] inside the loop view of any post type template.

add_shortcode('ds-parent', 'ds_top_level_terms');
function ds_top_level_terms() {
    $locations = 'test';
    $terms = get_the_terms(get_the_ID(), $locations);
    foreach ($terms as $term) {
        $parent = $term->parent;
        if ( $parent == '0' ) {
            $term_link = get_term_link($term, $locations);
            return $term->name;
        }
    }
}

CODE SNIPPED TO FETCH MID LEVEL TAXONOMY TERMS

  • Australia ( Parent)
    • Queensland (Child)
      • Brisbane ( Child of a child)

Here again, replace $location variable to your current taxonomy name and then use the shortcode [ds-middle-terms] inside the loop view of any post type template.

function ds_sort_terms(Array &$cats, Array &$into, $parentId = 0)
{
    foreach ($cats as $i => $cat) {
        if ($cat->parent == $parentId) {
            $into[$cat->term_id] = $cat;
            unset($cats[$i]);
        }
    }
    foreach ($into as $topCat) {
        $topCat->children = array();
        ds_sort_terms($cats, $topCat->children, $topCat->term_id);
    }
}
add_shortcode('ds-middle-terms', 'ds-middle-terms');
function ds-middle-terms( $atts ) {
    extract( shortcode_atts( array(
        'taxonomy' => 'abc'
    ), $atts ) );
  
 
$categories=get_the_terms(get_the_ID(), $taxonomy);

$categoryHierarchy = array();
ds_sort_terms($categories, $categoryHierarchy);
	$amiarray = array_values($categoryHierarchy);
	foreach($amiarray[0]->children as $final){
		return $final->name;
	}    
}

CODE SNIPPED TO GET BOTTOM LEVEL TERMS OF A HIERARCHY

  • Australia ( Parent)
    • Queensland (Child)
      • Brisbane ( Child of a child)

In the same way, replace $location variable to your current taxonomy name and then use the shortcode [ds-bottom-level] inside the loop view of any post type template.

add_shortcode('ds-bottom-level', 'ds_bottom_terms');
function ds_bottom_terms() {
   extract( shortcode_atts( array(
        'taxonomy' => 'abc'
    ), $atts ) );
  
 
$categories=get_the_terms(get_the_ID(), $taxonomy);

$categoryHierarchy = array();
sort_terms_hierarchicaly($categories, $categoryHierarchy);
	$amiarray = array_values($categoryHierarchy);
	
	foreach($amiarray[0]->children as $final){
		foreach($final->children as $finall){
			return $finall->name;
		}
		}
}

Now you can use above shortcodes in a post view loop of Toolset and can only show desired term levels.

If you need further assistance, write me down in the comments section or alternatively, you can contact me through my contact page of the website.

Cheers

Toolset launched Custom Types Training Course – Get 20% off on Toolset

Toolset has recently launched a “Custom Types Training” course for their users to know important techniques which could help them save time and produce better results. 

This course is mainly focused to let the users know about the power of “Custom Types”.

After going through this course, a basic user can progress to intermediate and then to advanced level.

What’s in the Course ?

This course consists of 5 chapters.

Check below in depth, what is covered in each of them:

What are Custom Types and how they work?
Creating Custom Post Types
  •  When and why you should use custom types
  •  How to create custom post types
  •  How to create custom fields
  •  How to create custom taxonomies
Displaying Content Types
  • How content is displayed in WordPress
  • Designing templates for single posts
  • Designing archives
  • Creating Custom Lists of Content
Connecting Different Types of Content
  • Easily building advanced sites by connecting different types of content
  • Different kinds of post relationships
  • How to connect different post types
  • Displaying Related Content
Creating Custom Searches
  • When and why you should use custom searches
  • How custom search works
  • How to create a custom search

COST

It is free for Toolset Clients. If you’re not (yet) using Toolset, then you can buy their course separately (it costs $29 USD).

BLESSING IN DISGUISE FOR WORDPRESS DEVELOPERS / FREELANCERS

This course is helpful for WordPress Developers / Freelancers who wants to enhance their development skills as by going through this course, they will be able to build many complex web applications using Toolset in short span of time.

Let me know your thoughts about Toolset and if you need assistance in using it, you can write your comments below.

Redirect from a primary domain to its subdomain

Redirect from a primary domain to its subdomain

Sometimes we find it really difficult to redirect from a main or primary domain to the subdomain of the same primary domain using .htaccess.

For example if you want to redirect from http://www.lynda.com to http://new.lynda.com

To achieve this, just grab this snippet and paste it in the .htaccess file in the root of your primary domain.

 

RewriteEngine On
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} ^(www\.)?lynda\.com$ [NC]
RewriteRule ^ http://new.lynda.com [R,L]

 

Post your comments below.

 

Toolset a Boon for WordPress Freelancers

Toolset a Boon for WordPress Freelancers

Its been 5 years when i started my carrier as a full time freelancer. Since then i have been working on Upwork when it was previously known as Odesk as a WordPress Developer and Designer.

PROBLEM

When i started my freelance business i used to build websites using some premium themes or customizing them as required by the clients and i was good at that. The only problem i used to face was that when a client asks for a custom theme development, it was not like that i didn’t knew how to code custom theme, it was actually the time it used to take and if i increase my budget, most of the times client refuses to pay that much and so to move forward (due to lack of income sources) i have to accept that, i had no option 🙁

The average time for a custom theme with some complex functionality was around 1 to 2 months depending on various factors. So as i was building websites for some of my clients using some premium themes in much lesser time but those websites were not so complex to make my portfolio stand out.

SOLUTION

Then i came to know about a plugin called Wp types which is one of the component of Toolset. I was able to build custom post types in seconds, add taxonomies to it and also custom fields without any hassle and in a matter of mins. There were other components as well like Views, CRED forms, Maps, Layouts and Access and they all combine to make a really powerful tool. You can learn more about their components and how powerful they are by visiting their website at https://wp-types.com/home/toolset-components/

I was able to build complex websites in a week with advanced functionality and also the biggest thing about this Toolset is that you don’t need to know PHP to use it ( however i am proficient in PHP) but good for someone who is a beginner or who knows just wordpress. I was able to build some really good complex websites in less than a week so it was like i can build 4 complex websites which was 4 times more than what i was able to do earlier.

Let it be any type of website like classifieds/ listing, Ecommerce or Directory website and almost all other niches. Toolset also offers some API hooks and very good support system which helps if you are stuck. It did boosted my freelance business.

However, it was easy for me to understand Toolset much faster and efficiently because i knew inside out of wordpress custom coding and how things work and now been working with Toolset since last 3 years i am now an expert in it.

So, if you are looking forward to boost your freelance business and build complex websites in less than a week without compromising the quality, go for toolset.

Have any questions do email me at amrinder146@gmail.com anytime.

Cheers

 

How to open woocommerce product links in new tab ?

How to open woocommerce product links in new tab ?

Hey there is always a question asked on many wordpress forums that how can we open a woocommerce product link in a new tab so that user can select other products as well rather than going back and forth again and again.

This is not an easy task to do for someone who is a designer and for a beginner wordpress developer or a client.

So i decided to come up with a solution using woocommerce hooks which is a standard way of doing any custom tweaks to woocommerce functionalities. 

Lets get started.

You just need to open your functions.php file and paste the below snippet into it.

I have used woocommerce_template_loop_product_link_open hook to achieve this and added target=”_blank” in the anchor tag which opens a link in new tab.

/* Open Products in New Tab Woocommerce-DevelopingSense */

remove_action( 'woocommerce_before_shop_loop_item','woocommerce_template_loop_product_link_open', 10 );
add_action ( 'woocommerce_before_shop_loop_item', 'ami_function_open_new_tab', 10 );
function ami_function_open_new_tab() {
echo '<a target="_blank" href="' . get_the_permalink() . '" class="woocommerce-LoopProduct-link">';
}

This is a best way to do it rather than using jquery or javascript which bloats a website.

Thanks and if you need any assistance you can contact me here.

WHERE I AM HOSTING MY WEBSITE ? IT IS ON SITEGROUND…CHECK MY REVIEW HERE

Do leave your valuable comments.