83 posts
  • Attended a Community Meetup
  • Australia
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
ThemeChills says

Hi everyone,

Does anyone know what script I could use for a custom shortcode which will allow me to use the “exclude” attribute similar to how the gallery shortcode does it?

Essentially, I am creating a slider which needs to exclude certain images that have been uploaded through my custom post type.

Currently, all images get included which is not what I need.

Hope you can help, thanks.

Leo

83 posts
  • Attended a Community Meetup
  • Australia
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
ThemeChills says

Just following up on this thread to see if anyone would know how to go about doing this?

612 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Sold between 10 000 and 50 000 dollars
ChapterThemes says

Why not let people only upload and setup images which need to be in the slider?

Or isn’t it a separate module/post type or something?

83 posts
  • Attended a Community Meetup
  • Australia
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
ThemeChills says

Why not let people only upload and setup images which need to be in the slider? Or isn’t it a separate module/post type or something?

So there are 2 sliders on the same page. I have setup the custom post type, where I can add all the corresponding images that will live in the slider.

Thing is, 1 slider needs to have 3 of the 6 images showing, and the other slider needs to do the same but in reverse.

Essentially, I want to replicate the functionality that the Gallery shortcode has, but cannot work it out.

I would like something like this:

[myshortcode exclude="21,32,43"]

Shortcode works, but it inherits ALL slides…does this clarify things?

1173 posts How's the surf doing?
  • Forum Superstar
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • United Kingdom
  • Referred between 200 and 499 users
  • Exclusive Author
  • Has been a member for 3-4 years
+2 more
tommusrhodus says

Realistically you’d need to post your codebase so we can see exactly how you’re doing things, but assuming you want to go for an ID array as the above to exclude items, I’m sure you could explode that string into an Array, and then use Unset:

http://uk3.php.net/unset

To remove images with those ID’s from your original array to be output?

83 posts
  • Attended a Community Meetup
  • Australia
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
ThemeChills says

Here is my code, without the ability to exclude…this displays ALL slides in my flexslider sections.


function chills_get_slider() {

    $output = '<div class="flexslider">
    <ul class="slides">';

    query_posts('post_type=slides');

    if (have_posts()) : while (have_posts()) : the_post(); 

    $the_featured_image = get_the_post_thumbnail( $post->ID, 'full' );
    $the_caption            = get_the_content();

    $output.='<li>'.$the_featured_image.'<p class="flex-caption">'.$the_caption.'</p></li>';

    endwhile; 
    endif; 
    wp_reset_query();

    $output.= '</ul>
    </div>';

    return $output;
}

And this is how I call the above function to render the output.


function chills_slider_shortcode($attr, $content = null) {

    $output = chills_get_slider();
    return $output;
}

add_shortcode('chills_slider', 'chills_slider_shortcode');

505 posts
  • Bought between 10 and 49 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

In the query posts you need to add the following:

'post__not_in' => array(6,2,8)

You would then grab the posts from the shortcode by using the Shortcode Attributes

1173 posts How's the surf doing?
  • Forum Superstar
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • United Kingdom
  • Referred between 200 and 499 users
  • Exclusive Author
  • Has been a member for 3-4 years
+2 more
tommusrhodus says
83 posts
  • Attended a Community Meetup
  • Australia
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
ThemeChills says

Also, use WP_Query instead of query_posts: http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts

Thanks guys.

So would I use this like so:


$query = new WP_Query( 'post_type=slides' );

Still new to all this, so apologies for all the questions.

Thanks again.

83 posts
  • Attended a Community Meetup
  • Australia
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
ThemeChills says

In the query posts you need to add the following:
'post__not_in' => array(6,2,8)
You would then grab the posts from the shortcode by using the Shortcode Attributes

Thanks Gareth,

Though how would this work if I need the user to exclude the required post ID. I wouldn’t be able to hard code it like so as the ID could differ.

Thoughts?

by
by
by
by
by
by