0

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

1 Answer 1

2

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'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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