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 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;

    endwhile;
    wp_reset_postdata();

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. :/

Thanks

share|improve this question

1 Answer 1

up vote 1 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

 
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.