WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to pull out all post ID's that have the same post title. This is in a custom post type called 'course-manager'. Here is what I have so far:

    $pages = array();

    $args1 = array(
        'post_type' => 'course-manager',
        'posts_per_page' => -1,
    query_posts( $args1 );
    $page = get_page_by_title( $current_post_title, 'OBJECT', 'course-manager' );
    while ( have_posts() ) : the_post(); //query all pages and get id's of pages with the specific title. Put id's in an array and use array in query below to query each id        
        $pages[] = $page->ID;
        echo $page->ID;


This should work in my opinion. I have four posts - two with the title I am searching for and 2 with a different title... however instead of getting the two differnt post ID's I want, I am getting 4 post ID's all the same. :/


share|improve this question
up vote 2 down vote accepted

Just change the $args array to this:

//Let's say you're searching the posts with the title 'The searched post':
$pages = array();
$args1 = array(
    's' => 'The searched post',
    'post_type' => 'course-manager',
    'posts_per_page' => -1
query_posts( $args1 );

Your query_posts will return all the posts with the title alike 'The searched post'.

share|improve this answer

Your Answer


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.