Skip to content

Instantly share code, notes, and snippets.

View shahadat014's full-sized avatar

Md.Shahadat Hossen shahadat014

  • ACS TEXTILES BD LTD.
  • Rupganj, Narayanganj, Dhaka
  • 00:51 (UTC +06:00)
View GitHub Profile
@shahadat014
shahadat014 / wordpress code
Created February 16, 2015 11:26
text shortcode into custompost
function test_shortcode($atts, $content = null){
extract( shortcode_atts( array(
'expand' => '',
), $atts) );
$q = new WP_Query(
array('posts_per_page' =>'9', 'post_type' =>'service')
);
@shahadat014
shahadat014 / wordpress code
Created January 27, 2015 10:25
wp register nav menu
register nav menu
<?php
function moderna_manus(){
register_nav_menus(array(
'main_menu' => 'Main Menu'
));
@shahadat014
shahadat014 / wordpress code
Created January 26, 2015 10:39
wordpress shortcodes code
<?php
function wishlist_shortcode($atts){
extract( shortcode_atts( array(
'expand' => '',
), $atts, 'wishlist' ) );
$q = new WP_Query(
array('posts_per_page' => '4', 'post_type' => 'wishlist-items', 'meta_key' => 'order_number','orderby' => 'meta_value','order' => 'ASC')
);
@shahadat014
shahadat014 / wordpress code
Last active August 29, 2015 14:13
Custom-posts-global-query
Custom-posts-global-query
<?php
global $post;
$args = array( 'posts_per_page' => -1, 'post_type'=> 'posttype', 'orderby' => 'menu_order', 'order' => 'ASC' );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<?php
$job_link= get_post_meta($post->ID, 'job_instructions', true);
@shahadat014
shahadat014 / wordpress code
Created January 18, 2015 19:31
To Get Author information
<?php the_author(); ?>
<?php echo get_avatar( get_the_author_email(), 'size here' ); ?>
<?php echo the_author_link(); ?>
<?php the_author_posts_link(); ?>
<?php the_author_meta( $field, $userID ); ?>
<?php the_author_meta('twitter'); ?>
<?php the_author_description(); ?>
<?php echo date("D M Y", strtotime(get_userdata(get_current_user_id( ))->user_registered)); ?>
@shahadat014
shahadat014 / wordpress code
Created January 18, 2015 19:29
Load jQuery and dependent JS libraries from function.php
<?php
wp_enqueue_script('jquery');
if (!function_exists('load_theme_scripts')) {
function load_theme_scripts(){
wp_enqueue_script( 'custom-script', get_template_directory_uri() . '/js/custom.js', array('jquery'), '1.0.0', true );
}
add_action("wp_enqueue_scripts", "load_theme_scripts");
}
?>
@shahadat014
shahadat014 / wordpress code
Created January 18, 2015 19:27
Not display some category products on the shop page
Category name(‘shirt’, ‘tshirt’, ‘pant’) which not to want display products on the shop page
add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
function custom_pre_get_posts_query( $q ) {
if ( ! $q->is_main_query() ) return;
if ( ! $q->is_post_type_archive() ) return;
@shahadat014
shahadat014 / wordpress code
Created January 18, 2015 19:26
Redirect to custom page
Redirect to custom page when user logged in
function login_redirect( $redirect_to, $request, $user ){
return home_url('custom-page-url-extension');
//Custom page url extension where want redirect
}
add_filter( 'login_redirect', 'login_redirect', 10, 3 );
@shahadat014
shahadat014 / wordpress code
Created January 18, 2015 19:24
Show author more post
Use in theme functions.php file
function get_related_author_posts() {
global $authordata, $post;
$authors_posts = get_posts( array( 'author' => $authordata->ID, 'post__not_in' => array( $post->ID ), 'posts_per_page' => 5 ) );
$output = '<ul>';
foreach ( $authors_posts as $authors_post ) {
$output .= '<li><a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a></li>';
}
@shahadat014
shahadat014 / wordpress code
Created January 18, 2015 19:22
Show all tags sorting by the number of post
<?php
$tags = get_terms( array("post_tag"), array("orderby"=>"count","order"=>"DESC"));
if ( !empty( $tags ) && !is_wp_error( $tags ) ) :
echo '<ul>';
foreach ( $tags as $tag ) :
echo '<li>' . $tag->name . '(' . $tag->count . ')</li>';
endforeach;
echo '</ul>';
endif;