Created
June 8, 2017 04:44
-
-
Save Mdimran41/1fc46ce67b929bac1f9efd21ddb65510 to your computer and use it in GitHub Desktop.
How To Register WordPress Custom Post Type | how to get data from a custom post type using new wp_query and php loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//include this code on functions. php for register a custom post type | |
function imran_slider_custom_post(){ | |
// register_custom_post_type | |
register_post_type('imran_post_type_name', array( | |
'labels' => array( | |
'name' => __( 'Sliders', 'textdomain' ), | |
'singular_name' => __( 'Slider', 'textdomain' ), | |
'add_new' => _x( 'Add New Slider', 'textdomain' ), | |
'add_new_item' => __( 'Add New Slider', 'textdomain' ), | |
), | |
'public' => true, | |
'supports' => array('title', 'thumbnail', 'editor', 'author', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes', 'post-formats' ) | |
)); | |
} | |
add_action( 'init', 'imran_slider_custom_post' ); | |
//loop for show data on website front end | |
$Avariablse = new WP_query(array( | |
'post_type' => array('imran_post_type_name'), | |
'post_per_page' => -1, //for show unlimited post | |
'posts_per_archive_page' => 10, | |
'order' => 'DESC', | |
'orderby' => 'date', | |
'offset' => 3, | |
)); | |
<?php if($Avariablse->have_posts());?> | |
<?php while($Avariablse->have_posts()) : $Avariablse->the_post();?> | |
<?php esc_attr(the_title());?> | |
<?php esc_attr(the_content());?> | |
<?php endif;?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment