• Home
  • About Me
  • Disclaimer
  • Privacy Policy
  • Portfolio Site
  • WordPress Development Service
  • WP Hosting

Banna360

WordPress Codes | Mobile App Reviews | Web, Android, iOS, Technology and More

Web, Android, iOS, Technology and More…

Mobile App Reviews | WordPress Codes

  • Home
  • Blog
  • iOS App Reviews
  • WordPress
  • Web Design
  • Web Development
  • PHP
  • General
  • Contact
You are here: Home / Wordpress / How to Create a Shortcode to Display Custom Post Type

How to Create a Shortcode to Display Custom Post Type

wordpress-codesIn this code snippet we are exploring how we can create a shortcode to display custom post type. With this code snippet we are utilising WordPress shortcode API.

What is WordPress Shortcode API

The API enables plugin developers to create special kinds of content (e.g. forms, content generators) that users can attach to certain pages by adding the corresponding shortcode into the page text.

The API handles all the tricky parsing, eliminating the need for writing a custom regular expression for each shortcode. Helper functions are included for setting and fetching default attributes. The API supports both self-closing and enclosing shortcodes.

What is WordPress Post type

WordPress can hold and display many different types of content. A single item of such a content is generally called a post, although post is also a specific post type. Internally, all the post types are stored in the same place, in the wp_posts database table, but are differentiated by a column called post_type.

Shortcode creation code to display custom post type

<?php

function abScrollingTestimonials() { 
    ob_start(); 
    $data = '<div class="testiScroller">'; 
        $query = new WP_Query('post_type=testimonial&showposts=5&orderby=rand'); 
            while( $query->have_posts() ):$query->the_post(); 
            $data .= '<div class="singleTestimonial" id="testomial-'.get_the_ID().'">'; 
                $data .= ab_improved_excerpt_nop(); 
                $data .= '<div class="clientDetails">- '.get_the_title().'<span>('.get_the_excerpt().')</span></div>'; 
            $data .= '</div>'; 
        endwhile; wp_reset_postdata(); 
    $data .= '</div>'; 
    return $data; 
 } 
add_shortcode('fadingTestimonials','abScrollingTestimonials');

?>

 

 

Filed Under: Wordpress Tagged With: shortcode api

Facebook Fans

Banna360

Recents Updates

Top backup plugins for WordPress

Contact Form 7 Boilerplate for Bootstrap CSS theme

GST For Freelancers and Service Sector

Display Related Post or Product based on Taxonomy in WordPress

Categories

  • Android App
  • Featured Post
  • General
  • iOS App Reviews
  • PHP
  • Web Design
  • Web Development
  • Wordpress

Android Apps

Friendly App review – The best alternative app for Facebook lite and messenger

If you are a person who likes to keep your personal life away from the work, Then Friendly App is for you. Multiple Facebook accounts on a single app, sounds great right? This app has a lot more to offer to make your Facebook experience even better. The Friendly For Facebook app is built by getting […]

My Jio App Review – The best way to track down your Jio Data usage

My Jio is an exclusive app from Reliance Jio digital service for its jio users where one can do tasks like keeping track on their usage to managing and recharging their Jio account. My Jio app had gone through many updates after its release, in the latest update for android the version 3.2.42 has nothing […]

About Me

Banna a professional Web developer with a specialization in WordPress web design, having worked on more than 200 individual WordPress projects and sites over the course of my career.As a specialist in WordPress development, I can help with all aspects of taking your WordPress project from start to finish.

READ MORE ABOUT ME

Recent Posts

  • UpdraftPlus – A Complete Study
  • Top backup plugins for WordPress
  • Contact Form 7 Boilerplate for Bootstrap CSS theme
  • GST For Freelancers and Service Sector
  • Display Related Post or Product based on Taxonomy in WordPress

Tags

autoupdate wordpress best translator app bhim app contact form 7 Friendly App review Gst freelancers LinkedIn redesign metabox my jio app MYSQL Productivity tips shortcode api upi app for ios whatsapp bug whatsapp uae why telegram wordpress.org wordpress hosting wordpress plugins wordpress tutorial zip using php

Copyright © 2025 · Magazine Pro Theme on Genesis Framework · WordPress · Log in