The default flow for adding a new post to Royal Slider is:
- Create and publish your new post
- Go into the Royal Slider-plugin and re-save your slider
This isn't very efficient, especially when you want to work with scheduled posts our even when working with different user roles (e.g. users without access to full website).
Hooks are available to update your slider when you save a post or during many other actions.
Extending this function to add custom posttypes with custom fields, we wrote this code:
function add_additional_posts_to_slider($slides, $options, $type) { // $options['id'] is the slider index if($options['id'] == 1) { $args = array( 'post_type' => '<custom_post_type>', 'post_status' => 'publish' ); $custom_slides = get_posts($args); $additiona_slides = []; foreach ($custom_slides as $custom_slide_object) { $additiona_slides[] = array( 'title' => get_field('slider_title', $custom_slide_object->ID), 'description' => get_field('slider_description', $custom_slide_object->ID), 'link' => get_field('slider_link', $custom_slide_object->ID), 'image' => array('attachment_id' => (string)get_field('slider_image', $custom_slide_object->ID)['id']) ); } if( is_array($additiona_slides) ) { $slides = array_merge($slides, $additiona_slides); } } return $slides; // slides that will be displayed in slider } add_filter('new_rs_slides_filter', 'add_additional_posts_to_slider', 10, 3);
Our solution makes it possible for our clients to create slides from a custom posttype. As soon as the post changes from 'Schedule' to 'Publish', the function does the rest.
Plugins:
- Royal Slider: plugin to create the slider
- Advanced Custom Fields: plugin to create custom fields for our custom posttype