The issue is with your $limit
var, you can’t set a default value like that because WordPress overwrites it with an empty value. Check out the Shortcode API for the correct way to pass and set shortcode attributes.
function custom_prev_posts( $atts ){
extract( shortcode_atts( array(
'limit' => 5
), $atts ) );
// the rest of your code, $limit now works correctly
}
You can also now set a custom limit by adding limit to your shortcode: [last5 limit=10]
Though last5 is an odd name for a shortcode that can display numbers of posts other than 5 🙂
Also, for future reference, enable debugging so you can see errors your code is generating.
Related Posts:
- How to fix ‘Notice: Undefined index:’ in PHP form action
- How to determine if WP_DEBUG is enabled? [duplicate]
- Pass a PHP variable to another file
- Using Global Variables Expensive for PHP
- One button to change all settings in theme customizer?
- Add custom image sizes to media uploader
- Export all post from database to JSON only when the database gets updated
- Multiple pages on one with different HTML
- Twitter feed is showing blank in WP site [closed]
- Unique key for each row in a repeater field
- Is $hook a global variable in WordPress
- Notice: wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder
- Show different Customizer Settings on Page-Tamplates
- Convert imploded plain text into links
- Add “last” and “first” to WordPress Comment Pagination Links
- PHP if Condition not working
- Extend a class of a plugin
- Include a php file from functions.php only to homepage
- Customizer Show/Hide
- How to get the Page Number of the Current Page in Single Post Pagination
- How to restrict page access to logged-in users?
- Ajax return code 400
- Handling Body class based on Template
- Is XAMPP faster than running LAMP in WSL on Windows 10? [closed]
- Changing layout with wp_customise
- Get updated query results on page after insert in database
- Reconfiguring WordPress site
- Use Icomoon external svg file with
- Show wp_die if url form comment not emply
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- How to split links generated into an xml sitemap to avoid exceeding 30 sec maximum execution time?
- Hacked WordPress website /Homepage redirect [closed]
- Database query works fine outside WordPress
- Loading index.php contents which located outside blog folder for post single page
- do_shortcode with custom field
- WordPress page content outside WordPress
- Pull Tags But Not as Links
- Define specific category name in PHP
- Can I get an email notification when media is uploaded to the media library?
- PHP Syntax Error on get_posts
- Shortcode to find and replace URL
- Don’t show certain div on front page?
- Function Reference Documenting Template Tags for use in Custom Theme Templates?
- Seo Friendly Filter URLs
- PHP contact form not redirecting [closed]
- Add value to new attribute inside WordPress menu items
- Please show me how to use an if/else statement in combination with wp_enqueue
- Add new post in existing categories using wp_insert_post
- I’m unable to call img path using single quotes in an array?
- Else/If Statement to Display Photo Descriptions
- PHP error with a shortcode: “no suitable wrapper” for file_get_contents
- Count foreach and display in menu php
- custom header text
- Display additional page templates and a sidebar on plugin activation
- Trying to copy linux blog locally with XAMPP – php fatal error
- unsetting actions (edit and trash) of specific posts from that list of all pages or posts based on each posts metabox value
- Add a Metabox checkbox to the Page Edit screen of wp-admin , which only certain roles can see and Makes only certain roles able to Edit said page
- Custom URL for multiple categories hierarchy
- if get_post_meta is empty echo a placeholder or shortcode
- Admin Panel 404 Error after login
- in_array not working on dev server but works on localhost
- PHP Warning: mysqli_query(): after updating my websites php from 5.6 to 7.2
- Categories does not show Block editor WordPress
- Foreach Loop Of Post Types With Nested If Else If Not Completing Process
- Unable to insert two value in two different columns (WordPress database)
- I cannot find the wordpress.scss file that my live site is pulling from
- WordPress Slick Slider + Magnific Popup
- Fix common misspellings/errors based on array of replacements
- Search for single post by 2 tags
- Import Instagram post as WordPress post
- How to put a before and after with tags in a wordpress entry?
- How to call a WP Class inside my theme
- HTML Formatting “single_term_title()”?
- Contactform7: display results from CURL
- Adding a widget under an ‘Add to Cart’ button through a PHP snippet
- How to update option field in database on clicking the publish button in customizer
- Allow Submit Contact Form Default Text In Text Box
- Woocommerce Related Product by 2 taxonomy
- Add ID to output only for first option
- Front end/Database connection in WP
- Display text of price (minus 20%) on every product page in a sentence.
- how use php query in AJAX jquery
- Div Missing In Custom Loop Query
- media_handle_sideload() returned post_id being incremented
- Add multiple JavaScript files to template header [duplicate]
- Can i show items based on the day with php?
- How can I add page template after post of a post type?
- How to add custom checkout field in user details mail template
- How to insert a variable into a query parameter?
- How to edit homepage in WordPress?
- Adding Custom JQuery Menu Fresh Slide Out
- Errors while Loading Most Recent Version of jQuery
- How I can give a php page a style from my theme
- Understanding responsive imagery
- How to get meta box labels?
- get_query_vars always retruns empty value
- How to group by column a and sum column b and c in a php array
- Convert custom field date format to “WordPress default”
- Woocommerce Convert existing order to the cart
- Execute function when I click button