Top Interview Questions and Answers

Top Interview Questions and Answers
Interview Sortout

Browsing "Older Posts"

Wordpress Advance Interview Questions and Answers

By Dhananjay yadav → February 5, 2018
How can we create a CTP in wordpress?
CTP means Custom Post Type. We can create our own custom post types in wordpress besides the default post. We have to use wordpress core to implement this feature. We can add Product type, property type using CTP .
Example is given as follows:
<?php
function create_post_type() {
      register_post_type( 'Custom CPT',
        array(
          'labels' => array(
            'name' => __( 'Name of your CPT' ),
            'singular_name' => __( 'Name of your CPT' )
          ),
          'public' => true,
          'has_archive' => true,
        )
      );
    }
?>
add_action( 'init', 'create_post_type' );


Write custom query to list recent five posts?
Using WP_Query() method we can create custom wordpress queries. An example is given below:
<?php
$args = Array('post_type' => 'post', 'posts_per_page' => '5' );
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) : 
   while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <?php endwhile; ?>
<?php else : ?>
    <p> no posts found</p>
<?php endif; ?>