wp --infowp theme update --allNavigate to wp-content/plugins/. Then run this command to create a new plugin called my-awesome-plugin.
wp scaffold plugin my-awesome-pluginwp plugin update --allCheck this example code.
/**
* List of views served by this composer.
*
* @var array
* @return array
*/class My_Shortcode{
public function __construct(){
$this->register_shortcode();
}
public function register_shortcode(){
add_shortcode('shortcode_tag', [$this, 'get_shortcode_output']);
}
public function get_shortcode_output($atts){
return "Hello world";
}
}
// Initialize the class
new My_Shortcode();👉 Open a template file for the currently active theme. Our targeted custom post types are 'bwl_kb' and 'portfolio'.
👉 We would like to use full-width template for those post types. So, we have edited the template-full-width.php file and
included the following code.
👉 The Template Post Type section in the commented area is allowing the custom post types to use the template-full-width.php file.
/**
*
* Template Name: Full Width Template
* Template Post Type: post, page, bwl_kb, portfolio
* The template for displaying the contents without any sidebar.
*
* @package BwlKdeskTheme
*/Now, if you go to the add/edit page of the portfolio or bwl_kb, you will be able to use the full-width template. ,🚀
Just change the text petitions to posts for displaying all the posts.
Check all your CPT REST routes dynamically.
GET /wp-json/wp/v2Returns a list of petition posts.
GET /wp-json/wp/v2/petitionsReturns the petition post with ID 123.
GET /wp-json/wp/v2/petitions/123Returns petitions assigned to the petitions_category term ID 10.
GET /wp-json/wp/v2/petitions?petitions_category=10Returns the second page with 5 petitions per page.
GET /wp-json/wp/v2/petitions?per_page=5&page=2GET /wp-json/wp/v2/petitions?orderby=date&order=desc
GET /wp-json/wp/v2/petitions?orderby=title&order=ascReturns petitions that contain the keyword child.
GET /wp-json/wp/v2/petitions?search=childGET /wp-json/wp/v2/petitions?meta_key=sign_count&orderby=meta_value_num_embed loads featured images, authors, and related objects to reduce additional calls.
GET /wp-json/wp/v2/petitions?_embedBy default, not all meta fields are available via REST API. You must register your _cmb_bptm_sign_lists meta key with show_in_rest => true when registering the meta.
function register_petitions_meta() {
register_post_meta('petitions', '_cmb_bptm_sign_lists', [
'type' => 'integer',
'single' => true,
'show_in_rest' => true, //Must be true
]);
}
add_action('rest_api_init', 'register_petitions_meta');🚧 Important Note:
You must need to enable custom-fields support while registering custom post type.
$support = [ 'title', 'thumbnail', 'comments', 'author', 'editor', 'custom-fields' ];Now, _cmb_bptm_sign_lists will be accessible as part of the meta object.



