Search
 
SCRIPT & CODE EXAMPLE
 

PHP

wordpress get custom post type posts

<?php 

$args = array(
    'post_type'=> 'services',
    'areas'    => 'painting',
    'order'    => 'ASC'
);              

$the_query = new WP_Query( $args );
if($the_query->have_posts() ) : 
    while ( $the_query->have_posts() ) : 
       $the_query->the_post(); 
       // content goes here
    endwhile; 
    wp_reset_postdata(); 
else: 
endif;

?>
Comment

add Custom post type wordpress

function iranelementor_posttype() {
 register_post_type( 'musics',
 array(
 'labels' => array(
 'name' => __( 'musics' ),
 'singular_name' => __( 'music' )
 ),
 'public' => true,
 'has_archive' => true,
 'rewrite' => array('slug' => 'musics'),
 )
 );
}
add_action( 'init', 'iranelementor_posttype' );
/*
* Creating a function to create our CPT
*/
function custom_post_type() {
// Set UI labels for Custom Post Type
 $labels = array(
 'name'                => _x( 'musics', 'Post Type General Name', 'twentythirteen' ),
 'singular_name'       => _x( 'music', 'Post Type Singular Name', 'twentythirteen' ),
 'menu_name'           => __( 'musics', 'twentythirteen' ),
 'parent_item_colon'   => __( 'Parent music', 'twentythirteen' ),
 'all_items'           => __( 'All musics', 'twentythirteen' ),
 'view_item'           => __( 'View music', 'twentythirteen' ),
 'add_new_item'        => __( 'Add New music', 'twentythirteen' ),
 'add_new'             => __( 'Add New', 'twentythirteen' ),
 'edit_item'           => __( 'Edit music', 'twentythirteen' ),
 'update_item'         => __( 'Update music', 'twentythirteen' ),
 'search_items'        => __( 'Search music', 'twentythirteen' ),
 'not_found'           => __( 'Not Found', 'twentythirteen' ),
 'not_found_in_trash'  => __( 'Not found in Trash', 'twentythirteen' ),
 );
// Set other options for Custom Post Type
 $args = array(
 'label'               => __( 'musics', 'twentythirteen' ),
 'description'         => __( 'music news and reviews', 'twentythirteen' ),
 'labels'              => $labels,
 // Features this CPT supports in Post Editor
 'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
 // You can associate this CPT with a taxonomy or custom taxonomy. 
 'taxonomies'          => array( 'genres' ),
 /* A hierarchical CPT is like Pages and can have
 * Parent and child items. A non-hierarchical CPT
 * is like Posts.
 */ 
 'hierarchical'        => false,
 'public'              => true,
 'show_ui'             => true,
 'show_in_menu'        => true,
 'show_in_nav_menus'   => true,
 'show_in_admin_bar'   => true,
 'menu_position'       => 5,
 'can_export'          => true,
 'has_archive'         => true,
 'exclude_from_search' => false,
 'publicly_queryable'  => true,
 'capability_type'     => 'page',
 );
 // Registering your Custom Post Type
 register_post_type( 'musics', $args );
}
add_action( 'init', 'custom_post_type', 0 );
Comment

showing custom post type in wordpress website

<?php 
$loop = new WP_Query( array( 'post_type' => 'graves', 'posts_per_page' => 10 ) ); 

while ( $loop->have_posts() ) : $loop->the_post();

the_title( '<h2 class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h2>' ); 
?>

    <div class="entry-content">
        <?php the_content(); ?>
    </div>

<?php endwhile; ?>
Comment

how to wp create post type in wordpress


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Our custom post type function
function create_posttype() {
 
    register_post_type( 'movies',
    // CPT Options
        array(
            'labels' => array(
                'name' => __( 'Movies' ),
                'singular_name' => __( 'Movie' )
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'movies'),
            'show_in_rest' => true,
 
        )
    );
}
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );
Comment

PREVIOUS NEXT
Code Example
Php :: define php 
Php :: error 500 internal server error in laravel 
Php :: pmxi_gallery_image 
Php :: get request header codeingiter3 
Php :: strip non numeric and period php 
Php :: laravel chunk 
Php :: yajra laravel datatables rawcolumn 
Php :: text box should accept only alphanumeric not special characters in php 
Php :: echo errors php 
Php :: how to add column to database in laravel 
Php :: php http method 
Php :: get date to current week last or first day dates 
Php :: job execute async laravel 
Php :: clear cache in laravel without artisan 
Php :: ci4 throw new exception 
Php :: laravel get second last record 
Php :: UUIDs LARAVEL 
Php :: php parse query string 
Php :: laravel optional params 
Php :: laravel invoice toturial 
Php :: Laravel API Endpoint "401 Unauthorized" on Server But Works Fine On Localhost 
Php :: laravel seeder 
Php :: laravel copy 
Php :: laravel 9 route group 
Php :: add custom shortcode in contact form 7 
Php :: get all error message in array form laravel validation in laravel 
Php :: laravel debugbar false 
Php :: php get multiple url parameters 
Php :: laravel manually authenticate user 
Php :: php send post request 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =