- 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
- Is there a action hook for the “Empty Trash” button?
- Remove Categories / Tags From Admin Menu
- How to display by default only published posts/pages in the admin area?
- Static text above category page
- How can you control what a user is allowed to post in the backend?
- wp query custom orderby not custom field
- Custom Post Type doesn’t use single.php or single-{custom_post_type}.php
- Customizing individual images on posts
- Hook To Get All Posts Deleted
- How to show content of specific item on the same page?
- How to retrieve custom field values and save again as array
- Meta boxes not saving
- Custom Select Query pagination not working properly
- Custom Single Post Type not referring to single-post-type.php File
- Custom URL Structure for posts with subcategories
- Help with a function that will place a map pin for all posts
- How to list all names and descriptions of a custom taxonomy
- Is there a Standard Format for Clean URLs for Archives of Custom Posts?
- How can I have the posts from one word press blog show on the presentation page of another word press site
- 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
- How to modify specific parts of a post content in WordPress
- Include post on external custom site
- How to show the posts list into a static page? Problems to use the loop into a static page
- Get new post meta data when (custom) post is saved
- Run Jquery Script after delete post in front end
- How do I control the fallback query after the original query returned cero posts?
- Checking if some condition is matched before inserting post into database
- Shortcode for printing post titles
- Adding The Post Template Dropdown to WP-Admin
- wordpress paginate, link to the right page
- Allow users to create their own page/s
- How to use extract shortcode in loop?
- “Current” class on a singular page menu item with custom post types?
- 404 for some custom taxonomy not ALL taxonomy
- Using Post ID and Page ID in same function
- Given two custom post types: Automatically add meta fields from one custom post type to another
- How to only allow post to be deleted if custom field doesn’t exist
- Display metabox with date
- Show a Category Specific Info Box
- Successive creation of over 1000 posts causes 404?
- Make a custom URL and link to custom Template
- Display only posts with comments
- How can i retrive the movies, trailers, news in a single page using search
- Change the default video URL in a post to shortcode format
- Special Query: Title, Terms, Content – %LIKE%
- Custom Post Title as search term
- Add default content to post (for specific category)
- How can I allow users (subscribers) to download selected posts into a single PDF? (RESOLVED)
- Setting default category for display
- Choose options via url
- Custom Post Type Pagination 404 Error (if paged>=2) [duplicate]
- adding custom meta as well as looping through posts
- Display ONLY Latest Post From Several Categories
- get post custom value
- WordPress strips some attributes for author posts
- First Custom Post Custom Fields Empty After New Custom Post
- Automatically delete default posts and pages on theme install?
- Best way to enable sorting by 3 criteria on a page of listings
- WordPress 3.2 – Problem with WYSIWYG editors in a custom post type?
- How to Do Custom Fields to Output a Definition List
- Display one post randomly from category on home page
- How do I add an article to specific page?
- How to show only the date, the title and a little “summary” of my WordPress post in my custom theme?
- How to have more post in a page than in your home page
- Deleting first four characters from all Post Titles
- Deleling wordpress posts permanently still have IDs
- How remove “recent comments” title without modifying code? [closed]
- get value from post to sidebar
- custom post type single page template not working
- WordPress Yoast SEO plugin Post Save/Update Issue
- If post has non-shortcode string
- Taxonomy Category category.php not working
- Insert Shortcode exactly at the end of the content
- Post’s arent displaying
- Display post structure in function
- Trying to create shortcode listing custom posts, but formating not being included
- Can I get custom post items in select box (dropdown)
- Only show posts belonging to multiple cateogries at same time
- How to have 2 posting pages on a blog
- Default post type doesn’t display in url
- How edit footer copyright info? [closed]
- Dynamic Menu Item
- How do I get content of custom post type through post ID
- Changes done in admin panel are taking time to reflect in the REST api responses
- Need to show birthday of custom post type(Famous people in this case) in elementor. Date of birth set in custom fields
- Simple shortcode to check if a user has commented on a certain post
- Undefined Function Fatal Error with Shortcode [closed]
- Notify/check if the content of a custom gutenberg block has changed on save_post
- I have a website issue I am trying to resolve
- How to use shortcode to get the second to newest post?
- WordPress Custom Post type csv exporter
- Edit Page button is gone
- How to set something to added automatically to the post
- Can`t attach image to a multiple posts
- How can I strip a single tag from an email post
- How do you export and import wordpress blog posts and exclude pagebuilder shortcodes?
- Shortcode in loop always display data of first post on the page