Get all posts containing a shortcode

WordPress isn’t aware of your shortcode until it’s rendered on the front end. So when WP sees it in the content and replaces it, that’s when it’s aware that your shortcode exists. It also promptly forgets about it afterward, of course.

So there’s no built in function to do what you’re asking. The best you can do is probably write a LIKE query which may or may not be a good idea.

<?php
function wpse87582_find_shortcode_posts()
{
    global $wpdb;
    return $wpdb->get_results("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%[your_shortcode_here%'", ARRAY_N);
}

Leave a Comment