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

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:

আসুন ওয়ার্ডপ্রেসের ড্যাশ বোর্ড পরিস্কার করি

ওয়ার্ডপ্রেসের এডমিন প্যানেলে লগিন করলেই একগাদা বক্স এসে হাজির হয়। যদিও স্ক্রিন অপশন থেকে সেগুলো সহজে তাড়ানো যায় কিন্তু যদি এমন হয় এডমিন নিজেই ড্যাশবোর্ড পরিস্কার করে রেখে দিলেন নতুন সদস্যের জন্য। তবে এই পরিস্কার এর কাজটা আমরা করবো সামান্য কিছু পিএইচপি কোডিং করে।

ধাপ একঃ প্রথমে আপনার থীমের functions.php ফাইলে এ ২টি ফাংশন লিখতে হবে। মনে রাখবেন প্লাগিন এর কোডগুলো চাইলে functions.php ফাইলেও লেখা যায়। তাহলে শুরু করা যাকঃ
[code language=”php”]
//Define the function which unsets the boxes
function remove_dashboard_widgets() {
global $wp_meta_boxes;
myprint_r($wp_meta_boxes);
/*
//unset($wp_meta_boxes[‘dashboard’][‘normal’][‘core’][‘dashboard_right_now’]);
# Remove plugins feed
unset($wp_meta_boxes[‘dashboard’][‘normal’][‘core’][‘dashboard_plugins’]);
unset($wp_meta_boxes[‘dashboard’][‘side’][‘core’][‘dashboard_plugins’]);
# Remove "WordPress News"
unset($wp_meta_boxes[‘dashboard’][‘normal’][‘core’][‘dashboard_primary’]);
unset($wp_meta_boxes[‘dashboard’][‘side’][‘core’][‘dashboard_primary’]);
unset($wp_meta_boxes[‘dashboard’][‘normal’][‘core’][‘dashboard_secondary’]);
unset($wp_meta_boxes[‘dashboard’][‘side’][‘core’][‘dashboard_secondary’]);
# Remove incoming links feed
unset($wp_meta_boxes[‘dashboard’][‘normal’][‘core’][‘dashboard_incoming_links’]);
unset($wp_meta_boxes[‘dashboard’][‘side’][‘core’][‘dashboard_incoming_links’]);

unset($wp_meta_boxes[‘dashboard’][‘side’][‘core’][‘dashboard_recent_drafts’]);
unset($wp_meta_boxes[‘dashboard’][‘normal’][‘core’][‘dashboard_recent_comments’]);
unset($wp_meta_boxes[‘dashboard’][‘side’][‘core’][‘dashboard_quick_press’]);
unset($wp_meta_boxes[‘dashboard’][‘normal’][‘core’][‘events_dashboard_window’]);
*/
}
// Now hook in to the action
add_action(‘wp_dashboard_setup’, ‘remove_dashboard_widgets’, 20, 0);

//better print_r function taken from
//http://stackoverflow.com/questions/1386331/php-print-r-nice-table
function myprint_r($my_array) {
if (is_array($my_array)) {
echo "<table border=1 cellspacing=0 cellpadding=3 width=100%>";
echo ‘<tr><td colspan=2 style="background-color:#333333;"><strong><font color=white>ARRAY</font></strong></td></tr>’;
foreach ($my_array as $k => $v) {
echo ‘<tr><td valign="top" style="width:40px;background-color:#F0F0F0;">’;
echo ‘<strong>’ . $k . "</strong></td><td>";
myprint_r($v);
echo "</td></tr>";
}
echo "</table>";
return;
}
echo $my_array;
}

[/code]
Continue reading

Show/Hide comment status text in wordpress

I am again confused if my post title is perfect or not 🙁 So let me explain, sometimes we disable comment for any post or page and at last the text shows “Comments are closed” or something else in different ways. But in commercial projects we need to follow some good design where in some posts or pages we may need to enable comment or not. So, let’s put a trick in theme to show the comment text(comment status in more smart way)

In latest wordpress version the loop is in the loop.php file in the theme folder. So for comment we will get this line

[code language=”php”]
<?php comments_template( ”, true ); ?
[/code]

But how about we put

[code language=”php”]
<?php if($post->comment_status == "open"){comments_template( ”, true );} ?>
[/code]

That means if comment is off then we will not show any text like “Comments are closed” . I strongly believe this trick will make the design clean in some condition 😛

Thank you