Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am developing a plugin, and I want to display a page that lists every page on the site that is using a specific shortcode defined by my plugin.

I assume that I need to manually search wp_posts, but I am curious if there is a built in function or a better way to do this.

Thanks so much!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You can specify a search term in a WP_Query or get_posts() call:

$pages = get_posts(
    array (
        's'         => '[shortcodename',
        'post_type' => array ( 'page', 'post' )
    )
);
share|improve this answer
    
Can this handle multiple search terms? '[shortcode' and a parameter with the shortcode. (I'd just do '[shortcode id=#', but there could be multiple parameters in any order). –  Jacob Raccuia Jun 10 '13 at 0:30
    
Yes, it should. Not sure what happens when only the parameters are found on page, but not the shortcode. Try it. –  toscho Jun 10 '13 at 0:32
    
I ran into the problem that id="1", id='1', and id=1 are all possible parameters, but are selective in search. Do you have any other ideas? Otherwise, this is working nicely, but I need some sort of this, this, or this for the id. –  Jacob Raccuia Jun 10 '13 at 1:43
    
As a work around, I'm going to just search for the shortcode, and search the array after that. Thank you! –  Jacob Raccuia Jun 10 '13 at 1:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.