Here is an example where I have created a custom post type called faq_categories.
in the settings for the custom post type, ensure the following is set to true:

  • Hierarchial
  • Rewrite Hierarchial


$args = array(
'post_type'=>array('faq', 'faqs'),
'taxonomy' => 'faq_categories',
'faq_categories' => 'patient'


if ( have_posts() ) : ?>

<!-- do something -->

<?php endif;


Published in Blog

wp_nav_menu( array(
'menu_class' => 'kt-nav main-menu clone-main-menu',
'container' => '',
'items_wrap' => '<ul class="%2$s">%3$s</ul>'
) );

Published in Blog
Saturday, 16 November 2019 02:36

Echo custom taxonomy values

$terms = get_the_terms( get_the_ID(), 'bake-lovers-categories' );
if ($terms) {
foreach($terms as $term) {
echo '<span class="tag">'.$term->name . ' '.'</span>';

Published in Blog
Thursday, 28 February 2019 06:13

Get the URL of a K2 extra field image

K2 extra fields can be a royal pain sometimes. They are not nearly as flexible as they should be. For instance, using the image extra field spits renders the image inside it's <img src /> tags. But what if you just want the URL of the image? Perhaps you need the image URL to use inside a CSS background image. Here's how:

Note that the alias of the extra field in my example is myImage. Change this to match your own custom field alias.
Also note that I am using this code inside a mod_k2_content module.

$fetchSrc1 = explode('src="', $item->extraFields->myImage->value);
$fetchSrc2 = explode('"', $fetchSrc1[1]);

<?php echo $fetchSrc2[0]; ?>

For using on K2 item pages, replace the first line with the following:

= explode('src="', $this->item->extraFields->myImage->value);

Published in Blog

Sometimes you need to know the category of the current K2 item, but reneder this information outside of the K2 template files. To check anything K2 outside of the K2 container, the code below is a good starting point.
By expanding this code a bit, you can check for all sorts of things, always from outside of the K2 container. For instance, I can use the following inside the <head> tags to trigger something specific to an item.

// Check if the item belongs to a specific category

// Gets component, view, and ID from the non-SEF URL
$whatComp = JFactory::getApplication()->input->get('option');
$whatView = JFactory::getApplication()->input->get('view');
$whatId = JFactory::getApplication()->input->get('id');
// Check if you are on K2 and viewing an item
if($whatComp == 'com_k2' && $whatView == "item") {
// Check the database for the category ID of the current K2 item
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->where($db->quoteName('id')." = ".$db->quote($whatId));
$myCatID = $db->loadResult();
// The number to be compared below is the ID of the category

if($myCatID == '17') {
// do something


Published in Blog

$parent = JTable::getInstance('K2Category', 'Table');
echo $parent->name;

Published in Blog
Sunday, 16 September 2018 00:42

Dynamic responsive alternating grid squares


  • Bootstrap 4 to create the grid columns
  • Flexbox to create the perfect responsibe squares that contain content
  • Wordpress plugin: Advanced Custom Fields to create a repeater field. The repeater field creates a pair of squares (an image square, and a text square). The repeater field contains sub fields for the various elements of the content (background image, heading, text, link etc)

Code over here

Published in Blog

Use the following snippet to display the URL of a custom post types taxonomy term. Just replace the word position with the name of the taxonomy.

$terms = wp_get_post_terms($post->ID, 'position');
foreach ($terms as $term) {
echo get_term_link($term);

Published in Blog

To display the results of a Toolset Types checkbox field, use the following in your PHP template:

$checkbox_value = types_render_field( "my_checkbox_field", array( "separator" => ", " ) );
echo $checkbox_value;

Taking it a step further, we can create conditionals based on values collected. In the following example I have four values:

$blacktown = types_render_field( "localities", array( "option" => "0" ) );
$carlingford = types_render_field( "localities", array( "option" => "1" ) );
$emerton = types_render_field( "localities", array( "option" => "2" ) );
$penrith = types_render_field( "localities", array( "option" => "3" ) );

if ($blacktown) {
// do something
if ($carlingford) {
// do something
if ($emerton) {
// do something
if ($penrith) {
// do something

Published in Blog
Friday, 23 February 2018 10:51

Using the WordPress wp_tag_cloud() Function

We all know that tags are a vital part of WordPress taxonomies, which are a way of grouping things together. Tags are created on the fly while creating posts and help us to locate similar posts linked by particular tags. Generally in a WordPress blog, different tags are grouped inside a tag cloud, and the size of each tag determines the frequency of its assignments to posts. Here we shall look into the correct usage of the wp_tag_cloud() function, which is responsible for all these tag clouds.

This is the main built-in function to display the tags associated with your recent posts, within the tag cloud.

The WordPress Codex wp_tag_cloud() page has a clear explanation of all the parameters of this function, but still let's quickly discuss the important ones.

  • 'smallest' – This parameter is of type integer and specifies the minimum text size of the tag in the cloud
  • 'largest' – This parameter is of type integer and specifies the maximum text size of the tag in the cloud
  • 'number' – This parameter specifies the total number of tags to be displayed in the cloud. You can specify it as '0' if you want all of them to be displayed
  • 'format' – This parameter specifies the format of the cloud display. It can be any of 'flat', 'list', or 'array'
  • 'separator' – This parameter specifies the separator within the tags in the cloud
  • 'topic_count_text_callback' – This parameter shows the number of posts associated with each Tag through a tooltip
  • 'taxonomy' – This parameter specifies the type of WordPress taxonomy which can be used within the tag cloud. Here the default is the 'post_tags' but you can use a custom taxonomy as well

These parameters play a key role in customizing the tag cloud.

WordPress has a default Tag Cloud widget which can be placed in the appropriate area of the page. But without using a widget you can use the wp_tag_cloud() function to display and customize the tag cloud in your blog. You can specify the parameters in a number of ways.

Parameters separated by '&' in one simple inline string.

Parameter specification in array format.

Specifying only selected parameters, the rest are kept as default.

Return the tag cloud as an array without displaying it in the blog. This result can be used later within the PHP code.

Create a function in your functions.php file and return the wp_tag_cloud() function. Once it is defined, you can call the function anywhere within your blog.

Now let us open our sidebar.php and call the function to display the tag cloud.

Let's add some CSS styling in our style.css file to make the tag cloud look more professional.

Now it looks like this:

Similarly using the same in the footer.php of our theme.

You can make it more beautiful by adding your custom CSS styles.

By adding different parameters within the wp_tag_cloud() function in the functions.php file we can customize our tag cloud. For example, if you like to include both your tags and categories into the tag cloud or rather the taxonomy cloud then the function can be written as:

Sometimes you do not like to keep the tag cloud in your sidebar or footer and creating a separate page for it keeps your blog clean. You can do so using the following method.

At first create a custom page template in your theme folder with the wp_tag_cloud() function. Here we have named the file tagcloud.php.

Now log in to your WordPress admin and go to Pages -> Add New. Put a good title for the page and then under the Page Attributes section choose the Template as Tag Cloud and then click on Update. That's it; your tag cloud page is ready. You can style the page with your own CSS styles.

Sometimes we want our users to select tags from a scrollable box in our sidebar. To accomplish this we have to create a function in our functions.php file.

In the above function we have considered the array format of the wp_tag_cloud() function, along with that the font size has been kept the same and the list has been ordered by name in ascending order.

Now open your sidebar.php and call this function.

Let us style it with some CSS.

Finally it looks like:

Thanks for reading and please feel free to suggest some more uses of this very useful wp_tag_cloud() function.

Published in Blog
Page 1 of 4