Hi all,

Hope you doing fine.

I am back again with wordpress stuff.

Some times, we need to list all category(terms) in one page.for that,it is really easy to do by function get_terms()

But problem is we need list with PaginationūüėÄ , For that we have to pass parameter offset and number in get terms function and that’s it..!

Here is Code:

if ( get_query_var( ‘paged’ ) )
$paged = get_query_var(‘paged’);
else if ( get_query_var( ‘page’ ) )
$paged = get_query_var( ‘page’ );
else
$paged = 1;

$per_page    = 2;
$number_of_series = count( get_terms( ‘mycategory’,array(‘hide_empty’=>’0’) ) );
$offset      = $per_page * ( $paged Р1) ;

// Setup the arguments to pass in
$args = array(
‘offset’¬†¬†¬†¬†¬†¬† => $offset,
‘number’¬†¬†¬†¬†¬†¬† => $per_page,
‘hide_empty’=>’0’
);

// Gather the series
$mycategory = get_terms( ‘mycategory’, $args );

// Loop through and display the series
foreach($series as $s)
{
$theurl = get_term_link($s, ‘mycategory’);
echo “<div class=\”ser-img img\” ><a href=\”” . $theurl¬† . “\”>”. $s->name .”</a>”;

}
echo “<br />”;
$big = 999999;
echo paginate_links( array(
‘base’¬†¬†¬† => str_replace( $big, ‘%#%’, esc_url( get_pagenum_link( $big ) ) ),
‘format’¬† => ‘?paged=%#%’,
‘current’ => $paged,
‘total’¬†¬† => ceil( $number_of_series / $per_page ) // 3 items per page
) );

 

In multilanguage website,generally when user click in language flag, all website content transaltes into perticular language.
for that purpose,we need to give many page title section and page content section as per number of language.It is done by plugin called Qtranslate,further more If we want to change meta field for each language we need use Plugin called (1) ACF and (2) ACF qtranslate

plugin that need to install:qtranslate,ACF(Advance Custom Field)

After installed plugins,
qtranslate:Add languages as per your requirement.For example 1.English(Language code:en) 2.Thailand(th). After add language we need to add post that has title and content in both language.
ACF : We need to add meta field for post or page.So, Let’s take Example:meta_key is ‘my_meta_key’.

 

Now after added single post in both language.we need to filter that post in front-end: means changes in codeūüôā
The post content will automatically change as per language change.
Now for post meta, here is code
in single.php

$arr=get_field( ‘pg_header’, $post->ID,¬† true );
print_r($arr);

For more :

¬† echo _e($term->description, ‘qtranslate’);

$content = apply_filters(‘the_content’, $about_us->post_content);

****WP MENU NAVIGATE/Pagiantion****************/
$linkarray=array();
$urlarray=array();
$locations = get_nav_menu_locations();

$menu = wp_get_nav_menu_object($locations[‘primary’]);¬† //Get menu items that menu location is set to ‘primary’
$menuitems = wp_get_nav_menu_items( $menu->term_id, array( ‘order’ => ‘DESC’ ) );

$i=-1;
foreach ( $menuitems as $item ){
if($item->type !=’custom’){
$i++;
$id = get_post_meta($item->ID,’_menu_item_object_id’,true).'<br />’;
$page = get_page($id);
$link = get_page_link($id);
$linkarray.=$id.”,”;
$urlarray.=$link.”,”;

if ($id==$post->ID){
echo ‘previd :’.$previd=$i-1;
$nextid=$i+1;
}
}
}

$linkarray=explode(‘,’,$linkarray);
$urlarray=explode(‘,’,$urlarray);

$nextid=$urlarray[$nextid];
if (empty($nextid)){
$nextid=$urlarray[0];
}
if($previd>0){
$previd=$urlarray[$previd];
if (empty($previd)){
$previd=$urlarray[$i];
}
}
?>
<a href=”<?php echo $nextid; ?>”>Next Item</a>
<?php if($previd>0){ ?>
<a href=”<?php echo $previd; ?>”>Previous Item</a>
<?php } ?>

/****************notification post type****************************/
function push_notification($post_id,$post) {

$blogusers = get_users( ‘blog_id=1&orderby=nicename&role=subscriber’ );
// Array of WP_User objects.
foreach ( $blogusers as $user ) {
$user_noti = get_user_meta($user->ID,’_user_noti’, true);
if(empty($user_noti)){ $user_noti = array(); }
if (in_array($post_id,$user_noti)) {
}
else{
array_push($user_noti,$post_id);
}
update_user_meta($user->ID,’_user_noti’,$user_noti);
//update_user_meta( $user->ID,’_user_noti’, $meta_value, $prev_value );
}

/*update_post_meta($post_id,’test’,$user->ID );*/

}
add_action(‘publish_notification’,’push_notification’,11,1);

function no_notification()
{

remove_action(‘publish_notification’,’push_notification’,11,1);
}
add_action(‘publish_to_publish’,’no_notification’);

//RECENT COMMENTS
$paged = ( get_query_var( ‘paged’ ) ) ? absint( get_query_var( ‘paged’ ) ) : 1;
$recent_comments = $wpdb->get_results(“select DISTINCT comment_post_ID from¬† wp_comments where comment_approved¬† =’1′¬†¬† ¬†ORDER BY comment_ID DESC “);

if ( count( $recent_comments ) > 0 )
{

$post_ids = array();
foreach ( $recent_comments as $comment )
{
$post_ids[] = $comment->comment_post_ID;
$posts_ids_array=array_unique( $post_ids );
}

// Query for the posts with the IDs collected
$posts_with_recent_comments = new WP_Query(array(
‘post__in’ => $posts_ids_array,
‘paged’ => $paged,
‘orderby’=>’post__in’
));
// Get your loop on
if ( $posts_with_recent_comments->have_posts() )
{
while ( $posts_with_recent_comments->have_posts() )
{
$posts_with_recent_comments->the_post();
$post_id = $post->ID;
$post_thumbnail_id = get_post_thumbnail_id( $post_id );
$img =¬† wp_get_attachment_image_src( $post_thumbnail_id, ‘thumbnail’);
if(empty($img[0])){
$img[0] = get_template_directory_uri().’/images/noimage.gif’;
}
get_template_part( ‘content’, get_post_format() );
}

$big = 999999999;
echo paginate_links( array(
‘base’ => str_replace( $big, ‘%#%’, esc_url( get_pagenum_link( $big ) ) ),
‘format’ => ‘?paged=%#%’,
‘current’ => max( 1, get_query_var(‘paged’) ),
‘total’ => $posts_with_recent_comments->max_num_pages,
‘prev_text’¬†¬†¬†¬†¬†¬†¬†¬†¬† => __( ‘Previous page’, ‘twentyfifteen’ ),
‘next_text’¬†¬†¬†¬†¬†¬†¬†¬†¬† => __( ‘Next page’, ‘twentyfifteen’ ),
) );
wp_reset_query();
}

}

add custom column in admin side

Posted: September 22, 2015 in Uncategorized

add_action( ‘admin_init’, ‘my_admin_init’ );
function my_admin_init() {
add_filter( ‘manage_edit-POSTTYPE_columns’, ‘my_new_POSTTYPE_column’);
add_action( ‘manage_POSTTYPE_posts_custom_column’, ‘POSTTYPE_column_info’, 10, 2);
}

function my_new_POSTTYPE_column( $column ) {
unset($column[‘comments’]);
unset($column[‘date’]);
unset($column[‘author’]);
$column[‘column1’] = ‘Column1 Name’;
$column[‘column2’] = ‘Column2 Name’;
$column[‘column3’] = ‘Column3 Name’;
$column[‘column4’] = ‘Column4 Name’;

return $column;
}

function POSTTYPE_column_info( $column_name, $post_id ) {
switch($column_name){
case ‘column1’:

echo “test”;
break;
case ‘column2’:
echo “test”;
break;
case ‘column3’:
echo “test”;
break;
case ‘column4’:
echo “test”;
break;
default:

break;
}
}

Auto draft post

Posted: September 19, 2015 in Uncategorized
Tags: ,

After admin login, when we go to wp-admin/post-new.php (for add new post) At that time one row in database is created.
and the entry was include new post id and post status is auto-draft.
And when we again refresh the page, none more row is created with new post id and post status