by Amrinder | May 19, 2020 | Code Snippets, Toolset |
Most of the users are facing this issue where the Toolset conditionals have suddently stopped working in Divi Builder. There is a technical reason behind it.
So this is how conditionals were used earlier by most of you guys.
OLDER WAY OF USING WPV TOOLSET CONDITIONALS
[wpv-conditional if="( $(wpcf-3d-tour-toolset) ne '' )"]View 3D walkthrough[/wpv-conditional]
LATEST WAY OF USING WPV TOOLSET CONDITIONALS
[wpv-conditional if="( $(wpcf-3d-tour-toolset).item($current_page) ne '' )"] View 3D walkthrough[/wpv-conditional]
The reason why Divi is not supporting the old way is because they are not declaring the current post variable. So in order to fix it, we need this minor alteration to the conditionals.
I hope this is helpful for you. If you need any help in Toolset or WordPress Web Development, you can contact me here.
by Amrinder | Aug 27, 2019 | Code Snippets, Toolset, Wordpress |
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
by Amrinder | Oct 28, 2017 | Code Snippets, Tips and Tricks |
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.
by Amrinder | Jul 18, 2017 | Code Snippets, Woocommerce |
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.
by Amrinder | Feb 19, 2017 | Code Snippets, Development, Wordpress |
This is a very common issue which happens when WordPress was not successfully updated. If this happens, then the admin is not able to log into wordpress dashboard as it redirects to this url Problem Solved: upgrade.php?_wp_http_referer=%2Fwp-admin%2F .
Below are simple steps to fix this issue in 2 minutes.
- Open File manager through hosting account or using FTP.
- Go to the wordpress installation directory and under wp-content folder, rename plugins folder to plugins123.
- Then go to your website url and write /wp-admin after the url.
You will see the dialog as below:

Click on UPDATE WordPress Database and the problem will be solved.
Cheers and comment for any issues.
by Amrinder | Oct 3, 2015 | Code Snippets, Tips and Tricks, Wordpress |
Moving a wordpress website is one of the common jobs in the freelance websites since many years.There are many blogs and tutorials explaining the process in detail either by video or by image presentation.
In this post, I will explain the basic steps to bear in mind while moving a wordpress website which are necessary to avoid any future problems.
- Always take a full backup of the website and database to be moved so that in case you run into any problems there is always a way back saving your precious hard work.
- Upload the files in the server.
- Update the htaccess file.
- If your current website is in the root of the main domain like for example it is as www.www.developingsense.com and it is to be moved to another domain for example www.thedeveloping.in, then there is no such need of updating the .htaccess file.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
&amp;amp;lt;/IfModule&amp;amp;gt;
# END WordPress
But if your current website is in the root directory of the domain and it has to be moved in any other folder of another domain like www.thedeveloping.in/wordpress, then the .htaccess has to be updated.
#BEGIN WordPress
RewriteEngine On
RewriteBase /theme/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /theme/index.php [L]
# END WordPress
- Now upload the exported database file to the new hosting using phpmyadmin.Do not forget to change the wp-options table rows. There you have to update the new website url in two places saying site_url and home_url.
- Now update the wp-config.php file in the root of the directory where wordpress is installed.Here you to write the new database name, hostname, username and password. This is where the database connection error occurs if it is not updated correctly.ik
Above are some of the basic steps we have to take care of while moving the wordpress website. Like we know, during migration many types of problems may occur due to different server configurations and thus never hesitate to follow up in the comments section below and i will be more than happy to help you out in that.
Any suggestions or mistakes found in this post reported will be appreciated.
Passion on HIGH