Search User by Display Name in WordPress Sitewide

In wordpress in backend or if you use wordpress user query ‘WP_User_Query’ by default it will not search by display_name even if you add display_name in “search_columns” field of WP_User_Query
So, this can be achieved by this small filter https://gist.github.com/manchumahara/9910185 (after add this code now if you search in your wordpress admin panel for user with their display name it will work)

ref: https://codex.wordpress.org/Class_Reference/WP_User_Query

Few lines I follow in my professional and personal life both

1. Respect others if you want to be respected by others, sorry respect is not a one way game. Love could be !
2. Be polite , it doesn’t need to waste dollar to be polite.
3. Try to listen to others , it could be important what others are thinking, sometimes you must listen to rudeness.
4. Learn from others even if they know less than you.
5. After a certain interval like 6 months or one year, Update yourself , re-index your learning, finding, dreams, friends, loved ones and your knowledge.
6. You can not earn faith from your surroundings by just applying some terms and conditions. Sometimes you have to earn that or achieve that. Before expecting believe from others think yourself do you believe them or do you know how to believe others. Sorry believe is not a one way game.
7. Learn how to say sorry.

I try to follow the above lines every day in my personal and professional life, both. When every time I re-index my life timeline I found I have changed my life , my thinking are changed (I will say it’s improved).

I thought those few lines may help others to change their thinking and livelihood.

Category Post Count in WordPress (Custom Taxonomy with Custom Post Type)

Let me explain my need in short:

I want to show post count for any category/any custom taxonomy registered for any custom post type. I searched wordpress forums and in google, found some solutions using

Nothing helped me such way, so I managed my own way with my little knowledge.

wp_get_productcat_postcount($id, $posttype = ‘product’, $taxname = ‘product_cat’)

$id = category or any taxonomy id(term id)
$posttype = post type name, example: post, page, or any custom post type
$taxname = taxonomy name or any category type name, for joomla default taxonomy it will category, post_tag, nav_menu, link_category, post_format, but we can use any custom taxonomy name as I used ‘product_cat’ which is used with custom post type ‘product’ , post type name.

[code lang=”php”]
function wp_get_productcat_postcount($id, $posttype = ‘product’, $taxname = ‘product_cat’) {

$result = wp_cache_get( ‘taxpostcount’.$id, ‘cbtaxpostcount’ );
//var_dump($resul);

if ( false === $result ) {

$args = array(
‘post_type’ => $posttype,
‘post_status’ => ‘publish’,
‘posts_per_page’ => -1,
‘tax_query’ => array(
‘relation’ => ‘AND’,
array(
‘taxonomy’ => $taxname,
‘field’ => ‘id’,
‘terms’ => array( $id )
)
)
);

$query = new WP_Query( $args);
/*
echo ‘<pre>’;

print_r($query->post_count);
echo ‘</pre>’;
*/
$result = (int)$query->post_count;

$cacheresult = wp_cache_set( ‘taxpostcount’.$id, $result, ‘cbtaxpostcount’ );
//var_dump($cacheresult);
}
return $result;
}
[/code]

Note: As I used wordpress object cache for better performance.

Thanks for reading, any comment is appreciable.

Google Plus Comment for WordPress

Google Plus Introduced Social comment plugin(unofficially). so I just made a small shortcode based plugin for wordpress to test the baby.

BTW, I noticed about this from google plus.

Download from bellow:

[download id=”36″]

Demo:
Please check here .

Shortcode:
[gpluscomment]

For more technical people
'url' => '', // leave empty for current post
'width' => '500',
'js' => 1,
'showarchive' => false,
'showhome' => false

My Test results screenshots:

Self Help+Push+Pull = Success

Problem: A man wants to climb a high wall, let see how he can do this 🙂

Step 1: Self Help + Passion + Self Motivation , yes I must do it, I just need to do it 😀

Step 2: Take help from a Friend 1 who can push from land, there may be someone , just search a bit 😛

Step 3: Take help from a Friend 2 who can pull from top of wall, and you are done.

BTW, I tried to help myself with pen & paper to draw the pictures, so don’t laugh if they looks funny 😛

jQuery Masonry doesn’t work with Bootstrap Hidden Tab

Ref: jQuery Masonry
I think many of you face issue with bootstrap hidden. After a hidden tab is made visible many things doesn’t work for the new visible content as it’s container was hidden, jquery or other js library fails to get various property, example: height, width etc and even some common issues like scrollbar, masonry etc script doesn’t work. So I have a solution for this.

Here is the common declaration about a bootstrap based tab.

[code language=”html”]
<div class="tabbable"> <!– Only required for left/right tabs –>
<ul class="nav nav-tabs">
<li class="active"><a href="#tab1" data-toggle="tab">Section 1</a></li>
<li><a href="#tab2" data-toggle="tab">Section 2</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab1">
<p>I’m in Section 1.</p>
</div>
<div class="tab-pane" id="tab2">
<p>Howdy, I’m in Section 2.</p>
</div>
</div>
</div>
[/code]

The above code will make a tabber based on BT. So now suppose in tab content pane we added Jquery Masonry. On first load the first tab will be visible and it’s masonry will work properly and 2nd tab will not as it should be actually but you will be unhappy about it and tear … 🙂 So here I am trying to how we can make this possible to work properly.

Let For adding masonry the html code for tab here.

[code language=”html”]
<div class="tabbable"> <!– Only required for left/right tabs –>
<ul class="nav nav-tabs">
<li class="active"><a masonid="mymasontabcon1" href="#tab1" data-toggle="tab">Section 1</a></li>
<li><a masonid="mymasontabcon1" href="#tab2" data-toggle="tab">Section 2</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab1">
<div id="mymasontabcon1">
<div class="itembox">hi there</div>
<div class="itembox">hi there</div>
<div class="itembox">hi there</div>
</div>
</div>
<div class="tab-pane" id="tab2">
<div id="mymasontabcon1">
<div class="itembox">hi there</div>
<div class="itembox">hi there</div>
<div class="itembox">hi there</div>
</div>

</div>
</div>
</div>
[/code]

Check in the above code for each anchor in li(tab) I added something like
masonid=”mymasontabcon1″ here attribute masonid is the div id of the div which we want to apply masonry. So suppose on dom ready we added masonry once.

Here we I did is calling the reload method of jquery masonry script but that need to be done after the tab’s container is shown. Otherwise we will not get proper output. I did this for each toggle of any tab, same thing is coded in the tab’s plugin included with BT.

[code language=”javascript”]
jQuery(document).ready(function(){
//this will certain happen when tab show method is done, that means we reload the masonry after the tab container is shown.
jQuery(‘body’).on(‘click.tab.data-api’, ‘[data-toggle="tab"], [data-toggle="pill"]’, function (e) {
e.preventDefault();
var mytarget = jQuery(this).attr(‘cbmasonid’);
//it is taken that already masonry is added in each tab.
jQuery("#"+mytarget).masonry(‘reload’ ); //here we call the reload method.
})
});
[/code]

Linkify url and hashtag for linkedin Status and share api

IF you are working with linkedin api and parsing status and share items for any user or company page then this small code will help to parse the status or share text (comes from api) to 1. linkify 2. Tagging 3. Linkify hashtag
Please note that linkedin doesn’t support any native @ handle for it’s own user based but all @ handle are for twitter user.
[code language=”php”]
/**
* Linkify url and hashtag
*
* @param type string $status_text
* @return type string
*/
function linkify_linkedin_status($status_text){

// linkify URLs
$status_text = preg_replace(
‘/(https?:\/\/\S+)/’,
‘<a href="\1">\1</a>’,
$status_text
);

// linkify twitter users
//please note that any thing tagged using @ in linkedin takes to twitter
$status_text = preg_replace(
‘/(^|\s)@(\w+)/’,
‘\1@<a target="_blank" href="http://twitter.com/\2">\2</a>’,
$status_text
);

// linkify hash tags
$status_text = preg_replace(
‘/(^|\s)#(\w+)/’,
‘\1#<a target="_blank" href="http://www.linkedin.com/signal/?keywords=%23\2">\2</a>’,
$status_text
);

return $status_text;
}
[/code]

jQuery TinyScrollbar doesn’t work in hidden container or tab or div : Why ?

Q: jQuery TinyScrollbar doesn’t work in hidden container or tab or div : Why ?

Answer:

I think this is problem  with jquery or as how the DOM works. When any parent div is hidden using css property display:block;  jquery can not determine the width, height etc for any child element (example div)  and this also happens for jquery tinyscrollbar plugin. I wasted almost 4/5 hours to get what the hell is happening as I was trying to add custom scrollbar in a tabber, tab tab tab … pa pa pa. But it was not working for inactive tabs (divs)

Solutions: After debuging jquerytinyscrollbar plugin’s js code I found

for method “update” it had code like

[code language=”javascript”]
oViewport[ options.axis ] = oViewport.obj[0][ ‘offset’+ sSize ];
oContent[ options.axis ] = oContent.obj[0][ ‘scroll’+ sSize ];
[/code]

and for hidden tab those oViewport.obj[0][ ‘offset’+ sSize ] and oContent.obj[0][ ‘scroll’+ sSize ] gives wrong height or width or just 0. So tha scrolling ratio doesn’t work which is calculated just after that like
[code language=”javascript”]
oContent.ratio = oViewport[ options.axis ] / oContent[ options.axis ];
[/code]

What we tried is we used another jquery plugin named jquery Actual which helps to get actual attributes of hidden element.
http://dreamerslab.com/blog/en/get-hidden-elements-width-and-height-with-jquery/

https://github.com/dreamerslab/jquery.actual/blob/master/jquery.actual.js

So add the jquery actual plugin first then include the jquery tinyscrollbar plugin. Now you need to be little brave to modify the jquery tinyscrollbar plugin.
So now update the update method like this

[code language=”javascript”]
oViewport[ options.axis ] = oViewport.obj[0][ ‘offset’+ sSize ];
oContent[ options.axis ] = oContent.obj[0][ ‘scroll’+ sSize ];

sSizecb = sAxis ? ‘width’ : ‘height’;
var oViewportaxis = $(oWrapper).children(‘div.viewport’).actual(sSizecb) ;
var oContentaxis = $(oWrapper).children(‘div.viewport’).children(‘div.overview’).actual(sSizecb) ;

oViewport[ options.axis ] = oViewportaxis;
oContent[ options.axis ] = oContentaxis;

[/code]

Download the full source code from here.

Also while adding tinyscrollbar I used some extra care, for inactive tabs more careeeeeeeeeeee.

Here are more sample codes if that helps ,
Please note that for making the scrollbar compatible with tinyscrollbar we need to add some extra div like “overview”

[code language=”javascript”]
jQuery(document).ready(function(){
//height is asumed 200px
//for scrollbar one, element id scrollbar1
jQuery(‘#scrollbar1’).children().wrapAll(‘<div class="viewport"><div class="overview"></div></div>’);
jQuery(‘#scrollbar1’).prepend(‘<div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div></div></div></div>’);
jQuery(‘#scrollbar1’).tinyscrollbarcb();

for scrollbar two , element id scrollbar2,
jQuery(‘#scrollbar2’).children().wrapAll(‘<div class="viewport"><div class="overview"></div></div>’);
jQuery(‘#scrollbar2’).prepend(‘<div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div></div></div></div>’);

jQuery(‘#scrollbar2’).children(‘div.viewport’).css({height:"200px"});
jQuery(‘#scrollbar2’).children(‘div.scrollbar’).css({height:"200px"});

jQuery(‘#scrollbar2’).children(‘div.scrollbar’).children(‘div.track’).css({height:"200px"});
jQuery(‘#scrollbar2’).tinyscrollbarcb();

});
[/code]

Thanks for reading.