How to create a custom query using shortcode

Have you ever tried to create a shortcode which create a custom worpress query?

Try with below code, i suggest the below code if you wish to show any articles/post to anywhere in the site using this shortcode.

You can get content using wordpress shortcode by passing your queries.

if(!function_exists ('custom_query')){
	function custom_query($atts)
		$result = '';
		global $post;
		$query = new wp_query($query_string);
		if($query->have_posts()) {
			while($query->have_posts()) { $query->the_post();
				$result.="<div class='post-item'>
<a href=".get_permalink()."><img width='100' height='100' src=".$meta." /></a>
<h1><a href=".get_permalink().">".get_the_title()."</a></h1>
<p class='metadata'><span class='post'>Posted by:</span>".get_the_author()."<span class='in-cat'>In:</span>".get_the_category_list(', ')."<span class='on-date'>On:</span>".get_comment_time()."<a href=".get_comments_link().">".get_comments_number('1 comment','2 comment','% comment')."</a></p>
<p>".get_the_content()."</p><p><a class='more-link floatright' href=".get_permalink().">Read More</a></p></div>";
		return $result;

You can use the shortcode [custom_query]

Example: [custom_query query_string=’cat=4′].

This will help you to create custom query using shortcode.

How To Make WordPress Theme Multilingual and WooCommerce Compatible

In this article you can learn about how to create a wordpress theme which is perfectly suitable for Woocommerce and WPML.

Before starting i would like to mention some points.

In order to have a multilingual woocommerce website you need to install the following plugins.

Woocommerce By Woothemes –

WPML By OnTheGoSystems,Inc. – (

Woocommerce Multilingual – (

WPML allows you to translate all the standard WordPress elements. This includes:

  • Menus
  • Standard widgets
  • Navigation elements
  • All texts wrapped in `gettext` calls
  • Post content including custom fields and taxonomy
  • Products
  • Theme options
  • Images and strings related to them

In order to have a WPML supported theme, you must follow the below conditions.

Add GetText Functions to Texts

For plugins or themes, be sure to wrap your hard-coded text in `gettext` functions. This includes the header, footer, and widget text. Your template files display an assortment of product information and hard coded text. For example, most templates will include the product name and a ‘buy’ link. The product name comes from the database, so you don’t need to worry about translating it.
Continue Reading…

How to extract zip files from server directly using php

All of servers not providing cpanel/GUI to access the files. Uploading through FTP will be a great deal and it will time consuming if there are number of files. For eg: if we are uploading CMS like WordPress, joomla, magento, there will be no of files (more than 2000+ files).

In this case i would suggest to upload the zip file via ftp and use a php extract method by adding the following code.

$zip = new ZipArchive();
$x = $zip->open('');//your zip file name here
if ($x === true) {
 $zip->extractTo(dirname(__FILE__)); // change this to the correct site path

This will reduce the delay in uploading.

How to get Youtube Subscriber Count Using PHP

You may be facing some situations in wordpress to display the total count of youtube subscribers, you can use the below code for display the youtube subscribers count.

echo $youtube_subscriber_count = json_decode(file_get_contents(''))->entry->{'yt$statistics'}->subscriberCount;

if you are looking for a function, don’t be afraid.

function getYouTubeSubscribers($channel, $stat = 'subscriberCount')
  return json_decode(file_get_contents('' . $channel . '?v=2&alt=json'))->entry->{'yt$statistics'}->$stat;

Total Video Views:
echo getYouTubeVideoViews('anandmahalakshmi');