Sunday, January 29, 2017

Friday, January 27, 2017

Lists all the Posts from Current Taxonomy

<?php $term = $wp_query->queried_object;
   $getterm = $term->slug;
?>
<?php $args = array(
    'post_type' => 'product',
  'tax_query' => array(
      array(
          'taxonomy' => 'product_category',
          'terms' => $getterm,
          'field' => 'slug',
      )
  ),
    );
$product_latest = new WP_Query( $args ); ?>
<?php while( $product_latest->have_posts() ): $product_latest->the_post(); ?>
 // Your content goes here
<?php endwhile; ?>

Thursday, January 26, 2017

Wordpress- hook to auto login after registration

function _new_user_auto_log_in($user_id){ if(!is_user_logged_in()){ $secure_cookie = is_ssl(); $secure_cookie = apply_filters('secure_signon_cookie', $secure_cookie, array()); global $auth_secure_cookie; $auth_secure_cookie = $secure_cookie; wp_set_auth_cookie($user_id, true, $secure_cookie); $user_info = get_userdata($user_id); do_action('wp_login', $user_info->user_login, $user_info); } } add_action('user_register', '_new_user_auto_log_in');

Replace Default WordPress Logo in the Login Dashboard Page

function custom_loginlogo() {
echo '';
}
add_action('login_head', 'custom_loginlogo');
add_filter( 'login_headerurl', 'custom_loginlogo_url' );
function custom_loginlogo_url($url) {
    return 'http://www.your-site-url.com';
}

How to Stay Logged in for Longer Period in WordPress

// Stay logged in for longer periods
add_filter( 'auth_cookie_expiration', 'keep_me_logged_in' );
function keep_me_logged_in( $expirein ) {
    return 31556926; // 1 year in seconds
}

Contact Form 7 Bootstrap Button

$(document).ready(function(){
$(".wpcf7-submit").addClass("btn btn-primary");
});

Monday, January 23, 2017

display latest post excluding current post

<?php $args = array(
    'post_type' => 'product',
    'posts_per_page' => -1,
    'post__not_in'   => array( get_queried_object_id() ),
);
$product_latest = new WP_Query( $args ); ?>
<?php while( $product_latest->have_posts() ): $product_latest->the_post(); ?>
<h3><?php the_title(); ?><h3>
<?php the_content(); ?>
<?php endwhile; ?>

Register Taxonomy for Custom Post Type

//Register Taxonomy for Product Post Type
add_action( 'init', 'product_taxonomies', 0 );
function product_taxonomies() {
    register_taxonomy(
        'reviews_category',
        'reviews',
        array(
            'labels' => array(
                'name' => 'Product Category',
                'add_new_item' => 'Add Product Category',
                'new_item_name' => "New Product Category"
            ),
            'show_ui' => true,
            'show_tagcloud' => false,
            'hierarchical' => true
        )
    );
}
Display Taxonomy
    <ul class="clearfix"> <?php echo get_the_term_list( $post->ID, 'product_category', '<li class="">', ', ', '</li>' ) ?> </ul>