Skip to main content

Posts

Showing posts from 2018

Add custom pagination to wordpress

$links = paginate_links( array(               'prev_next'          => false,               'type'               => 'array'             ) );             if ( $links ) :                 echo '<ul class="pagination">';                 // get_previous_posts_link will return a string or void if no link is set.                 if ( $prev_posts_link = get_previous_posts_link( __( 'Previous Page' ) ) ) :                     echo '...

FUNCTION TO GET DATE RANGE BETWEEN TWO DATES

/********************** FUNCTION TO GET DATE RANGE BETWEEN TWO DATES STARTS HERE ***************************/ function createDateRangeArray($strDateFrom,$strDateTo) {     // takes two dates formatted as YYYY-MM-DD and creates an     // inclusive array of the dates between the from and to dates.     // could test validity of dates here but I'm already doing     // that in the main script     $aryRange=array();     $iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2),     substr($strDateFrom,8,2),substr($strDateFrom,0,4));     $iDateTo=mktime(1,0,0,substr($strDateTo,5,2),     substr($strDateTo,8,2),substr($strDateTo,0,4));     if ($iDateTo>=$iDateFrom)     {         array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry         while ($iDat...

Function to add redirect url

function redirect ( $url ) { if (! headers_sent ()) { //If headers not sent yet... then do php redirect header ( 'Location: ' . $url ); exit ; } else { //If headers are sent... do javascript redirect... if javascript disabled, do html redirect. echo '<script type="text/javascript">' ; echo 'window.location.href="' . $url . '";' ; echo '</script>' ; echo '<noscript>' ; echo '<meta http-equiv="refresh" content="0;url=' . $url . '" />' ; echo '</noscript>' ; exit ; } }   // How to use $url = "www.google.com" ; redirect ( $url );

Plugins for use

Theme my login : for login purpose Advanced custom fields : for custom field Nav Menu Roles: for show navigation according to roles Wordpress access control: for show pages according to user roles User role editor: to set permissions according to user roles Redirect after login: to redirect after login according to user roles Flamingo : for saving contact form 7 forms to database Tabs portfolio - filterable portfolio plugin free Remove Dashboard Access

Pagination with custom loop

<? php //get the current page $paged = ( get_query_var ( 'paged' )) ? get_query_var ( 'paged' ) : 1 ; //pagination fixes prior to loop $temp = $query ; $query = null ; //custom loop using WP_Query $query = new WP_Query ( array ( 'post_status' => 'publish' , 'orderby' => 'date' , 'order' => 'ASC' ) ); //set our query's pagination to $paged $query -> query ( 'post_type=post&posts_per_page=5' . '&paged=' . $paged ); if ( $query -> have_posts () ) : while ( $query -> have_posts () ) : $query -> the_post (); ?> <li> <? php if ( has_post_thumbnail ()) : ?> <? php the_post_thumbnail ();?> <? php endif ; ?> <div class = "someclass" > <h2> <? php the_title (); ?> </h2...

To show custom field in posts table in Dashboard

/**** function to show custom field in posts table starts here******/    add_filter('manage_posts_columns', 'bs_event_table_head'); function bs_event_table_head( $defaults ) {     $defaults['status']  = 'Status';     return $defaults; } add_action( 'manage_posts_custom_column', 'bs_event_table_content', 10, 2 ); function bs_event_table_content( $column_name, $post_id ) {     if ($column_name == 'status') {     echo get_post_meta( $post_id, 'status', true );     } } /**** function to show custom field in posts table ends here******/    if post type - team replace:  manage_team_posts_columns, manage_team_posts_custom_column

dd function

/*****for printing array values starts here****/ function dd($val, $die = ""){     echo "<pre>";         print_r($val);     echo "</pre>";     if($die == ""){         die();     } } /*****for printing array values ends here****/

It is for displaying and updating the custom user meta data.

// Hooks near the bottom of profile page (if current user) add_action('show_user_profile', 'custom_user_profile_fields'); // Hooks near the bottom of the profile page (if not current user) add_action('edit_user_profile', 'custom_user_profile_fields'); // @param WP_User $user function custom_user_profile_fields( $user ) { ?>     <table class="form-table">         <tr>             <th>                 <label for="code"><?php _e( 'App Store Link to VR App' ); ?></label>             </th>             <td>                 <input type="text" name="user_app_store_link" id="user_app...