Title: Setting default arguments
Last modified: August 24, 2016

---

# Setting default arguments

 *  Resolved [canaryninja](https://wordpress.org/support/users/canaryninja/)
 * (@canaryninja)
 * [11 years ago](https://wordpress.org/support/topic/setting-default-arguments/)
 * Thanks for a great plugin Bill.
 * Could you give an example of how to write a filter function to make use of shortcode_atts_display-
   posts and set a couple of default arguments please?
 * I’ve tried creating one in functions.php and it successfully sets the two arguments
   I define in it but then seems to wipe all other arguments and ignore any that
   I specify in the actual shortcode.
 * Thanks
 * [https://wordpress.org/plugins/display-posts-shortcode/](https://wordpress.org/plugins/display-posts-shortcode/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Bill Erickson](https://wordpress.org/support/users/billerickson/)
 * (@billerickson)
 * [11 years ago](https://wordpress.org/support/topic/setting-default-arguments/#post-6176763)
 * Here’s an example of how it’s used: [http://www.billerickson.net/code/change-default-attributes-in-display-posts-shortcode/](http://www.billerickson.net/code/change-default-attributes-in-display-posts-shortcode/)
 * I think your issue was you were directly overwriting the $out (first parameter),
   which is exactly how you’d override whatever settings have been made in the shortcode.
 * There’s three parameters passed to the filter:
    1) the current shortcode attributes
   after the defaults and user-defined attributes have been combined ( $out ) 2)
   the list of supported parameters and their default settings, as defined in the
   plugin ( $pairs ) 3) the list of user-defined attributes specified by the user
   on this specific shortcode ( $atts )
 * What you want to do is create your own list of parameters and their default values,
   then for each parameter see if the user has specified a value for that. If they
   have, keep using the user’s value in the final list ($out). If they haven’t, 
   use your default value in the final list.
 * Hope that helps
 *  Thread Starter [canaryninja](https://wordpress.org/support/users/canaryninja/)
 * (@canaryninja)
 * [11 years ago](https://wordpress.org/support/topic/setting-default-arguments/#post-6176864)
 * Brilliant, worked a treat!
 * Might be worth adding a link to that code sample on your wiki page.
    [https://github.com/billerickson/Display-Posts-Shortcode/wiki#further-customization](https://github.com/billerickson/Display-Posts-Shortcode/wiki#further-customization)
 * Thanks for your help.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Setting default arguments’ is closed to new replies.

 * ![](https://ps.w.org/display-posts-shortcode/assets/icon-256x256.jpg?rev=2940963)
 * [Display Posts - Easy lists, grids, navigation, and more](https://wordpress.org/plugins/display-posts-shortcode/)
 * [Support Threads](https://wordpress.org/support/plugin/display-posts-shortcode/)
 * [Active Topics](https://wordpress.org/support/plugin/display-posts-shortcode/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/display-posts-shortcode/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/display-posts-shortcode/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [canaryninja](https://wordpress.org/support/users/canaryninja/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/setting-default-arguments/#post-6176864)
 * Status: resolved