- You enter second parameter in add shorcode is incorrect,you missing callable function in parameter.
- Like below this add_shortcode with parameter.
add_shortcode( string $tag, callable $callback );
Code :
function cpt_content_func($atts){
$post="";
$content="";
extract( shortcode_atts( array(
'slug' => null,
), $atts ) );
$args = array(
'post_type' => 'location',
'posts_per_page' => 1,
'post_name__in' => $atts['slug'] );
$post = get_posts( $args );
if ( !empty( $post ) ) {
$content = $post[0]->post_content;
}
return $content;
}
add_shortcode('stefan_location','cpt_content_func');
Related Posts:
- Stop WordPress automatically adding tags to post content
- WordPress removing tags?
- Setting Custom Sort Order of Posts within a Category
- Custom permalink structure only for default posts
- Exclude drafts in all() view of edit.php
- How to change the layout and styling of posts according to their category in WordPress?
- adding a custom css class to post
- Prevent duplicate posts in wp_insert_post using custom fields
- Add default content to post (for specific category)
- Pagination not working on Custom Page Template
- Display custom post types by date field
- display order of connections
- Adding variable for post title so post template can include auto-generated link to view on external website.com/{post title}
- same template for multiple custom post type single
- How to place HTML below the title of the (custom) post overview
- How to get a nofication when post submitted
- Is there any WordPress alternative to Book module of Drupal?
- .current-menu-item class on custom post type children pages – again?
- Display page content AFTER a loop of posts
- Run a function when post is deleted?
- How to start with post number x?
- How can I create custom button in post.php
- how to replace embedded “full” sized images within a post with the “large” ones
- Downgrade user from role that allows post creation
- Best way of deletion of old posts [closed]
- Animated gif for a thumbs
- Sidebar links for different pages
- Duplicating Table of Contents for Paginated Post
- Deleted category by mistake, all posts now have categorized category. Can i revert that?
- I am unable to publish/update post
- Delete post by giving its link
- Get posts of ONE taxonomy term of custom post type
- WordPress Custom Fields (Checkboxes with multiple values)
- How to make classes for posts?
- Custom Post Archive Page not working
- Adding buttons to Add New Post and Add New Page
- Getting Custom Post Loop to display in Bootstrap 3 column grid
- WordPress custom Query for Posts in Category display posts multiple times
- Editing the default page to show all posts, rather than most recent ones
- Automatically add date to the auto generation of post slug
- How could I change my Permalink from blog to custom structure? [closed]
- Add a custom meta box in the post options that loads some html code in the header
- Static posts page with home.php
- WordPress Multisite – Create Default Post and New Category On New Site Install
- Thumbnail & Category link aside post
- Shortcode to display the latest news article within a page
- Shortcodes on my website stops working after theme update [closed]
- How to get ID of the page included with get_page()?
- Is there a way to create a meta box that can be added multiple times to a post dynamically?
- WordPress custom post type with folder structure in slug
- Shortcode with ‘year’ parameter
- How to add automatically bootstrap 4 order-lg-1 and order-lg-2 classes for columns in foreach loop based on the count?
- Is it possible to add a shortcode below post title?
- WordPress 302 Redirect to Random Product/Post/Page
- Show custom post with custom categories with specific slug
- Display the 2nd category name of a custom post type without error if its null?
- How to call posts under a specific category on static front page?
- Querying another post category to match current post and display in loop
- Optimize CPT-function with a loop
- Add post tags to previously created custom post type
- Simple Custom Metabox Not Saving
- How to display only one category in a custom post type?
- Shortcode for tables which can include comma and linebreaks
- Custom Post Type Single Loop Outputting Wrong Post
- WordPress Post Deletion Issue
- How Can I Always Display A Particular Post First Using WP_Query?
- MySQL: Possible to replace all of wp_posts.post_content(id#) via UPDATE + REPLACE + SELECT?
- Change modified date to current date when title updated automatically
- Turn off display for custom sidebar post widget when on the post it’s displaying
- Change published date and time using SQL query for page in every 5 hour
- How to bulk Update URLs to new values?
- How to put the author of the post in the comments?
- Function is printing twice – any suggestions?
- Include Recent Post in Category
- How to create custom search form function including post “tags”
- How to invoke a HTML custom button based on a HTML dropdownlist menu
- Please I want to prefix my WP posts title according to each category
- Custom Post Type Rewrite URL
- Custom Post Types and Broken Permalinks
- The first post appears twice
- Customizing URL slugs of Custom Post Type and Taxonomy make posts/pages 404
- Show Posts By Custom Field
- Custom Post Type doesn’t use single.php or single-{custom_post_type}.php
- How to retrieve custom field values and save again as array
- Is there a Standard Format for Clean URLs for Archives of Custom Posts?
- Customize search results to include custom posts and display in a specific template page
- Custom permalink based on custom post type fields
- Add category attribute to custom recent post shortcode
- Checking if some condition is matched before inserting post into database
- Using Post ID and Page ID in same function
- How to only allow post to be deleted if custom field doesn’t exist
- Change the default video URL in a post to shortcode format
- Custom Post Title as search term
- adding custom meta as well as looping through posts
- How remove “recent comments” title without modifying code? [closed]
- Trying to create shortcode listing custom posts, but formating not being included
- How edit footer copyright info? [closed]
- Dynamic Menu Item
- Undefined Function Fatal Error with Shortcode [closed]
- I have a website issue I am trying to resolve