Title: Exclude current post ID dynamically
Last modified: August 24, 2016

---

# Exclude current post ID dynamically

 *  Resolved [robpinney](https://wordpress.org/support/users/robpinney/)
 * (@robpinney)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/exclude-current-post-id-dynamically/)
 * I’m trying to use ALM at the bottom of single posts to load a couple of other
   items, but I can’t figure out how to exclude the current post ID (which will 
   change). There is [another thread on this](https://wordpress.org/support/topic/how-to-load-only-posts-not-already-on-the-page?replies=6)
   already, but I’m struggling to adapt that code.
 * The shortcode I need to use is: `[ajax_load_more post_type="post" orderby="rand"
   posts_per_page="2" pause="true" max_pages="0" transition="fade" button_label="
   More"]`
 * Any help greatly appreciated!
 * [https://wordpress.org/plugins/ajax-load-more/](https://wordpress.org/plugins/ajax-load-more/)

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

 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/exclude-current-post-id-dynamically/#post-6000792)
 * Hi Rob,
    You need to store the current post id in a variable and then pass down
   the page to the shortcode.
 * in your single loop at the top of the page…
 * `<?php $exclude = get_the_ID(); // the post id ?>`
 * and now the ALM part…
 * `<?php echo do_shortcode('[ajax_load_more post_type="post" orderby="rand" posts_per_page
   ="2" exclude="' . $exclude . '" pause="true" max_pages="0" transition="fade" 
   button_label="More"]') ?>`
 *  Thread Starter [robpinney](https://wordpress.org/support/users/robpinney/)
 * (@robpinney)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/exclude-current-post-id-dynamically/#post-6000793)
 * Thank you so much! That’s the quickest and best support I could possibly have
   hoped for.
 * The only problem left is that it isn’t loading a custom field (‘location’) – 
   is there a way to get it to pull this data also?
 * Thanks again.
 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/exclude-current-post-id-dynamically/#post-6000795)
 * Define `global $post;` in your repeater template after the opening html tag.
 * Feel free to leave me a review 🙂
    [https://wordpress.org/support/view/plugin-reviews/ajax-load-more](https://wordpress.org/support/view/plugin-reviews/ajax-load-more)
 *  Thread Starter [robpinney](https://wordpress.org/support/users/robpinney/)
 * (@robpinney)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/exclude-current-post-id-dynamically/#post-6000796)
 * Indredible, thank you! I’ll be sure to leave a review.

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

The topic ‘Exclude current post ID dynamically’ is closed to new replies.

 * ![](https://ps.w.org/ajax-load-more/assets/icon-256x256.png?rev=2944639)
 * [Ajax Load More – Infinite Scroll, Load More, & Lazy Load](https://wordpress.org/plugins/ajax-load-more/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ajax-load-more/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ajax-load-more/)
 * [Active Topics](https://wordpress.org/support/plugin/ajax-load-more/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ajax-load-more/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ajax-load-more/reviews/)

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * 4 replies
 * 2 participants
 * Last reply from: [robpinney](https://wordpress.org/support/users/robpinney/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/exclude-current-post-id-dynamically/#post-6000796)
 * Status: resolved