Title: Query posts by title?
Last modified: August 19, 2016

---

# Query posts by title?

 *  [velocitykendal](https://wordpress.org/support/users/velocitykendal/)
 * (@velocitykendal)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/query-posts-by-title/)
 * I.d like to be able to query posts from a custom post type by their title, to
   list posts that share the same string in the title as the page I’m on. Something
   like this:
 * `<?php $thetitle = the_title(); ?>`
    `<?php query_posts("post_type=myposttype&
   post_title=$thetitle"); ?>` `<?php while (have_posts()): the_post(); ?>`
 * …but obviously the ‘post_title’ parameter doesn’t exist. Is there another way
   to do this? I’m a bit of a novice when it comes to PHP.
 * Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Moderator [t-p](https://wordpress.org/support/users/t-p/)
 * (@t-p)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/query-posts-by-title/#post-1795913)
 * documentation:
    [http://codex.wordpress.org/Function_Reference/query_posts](http://codex.wordpress.org/Function_Reference/query_posts)
 *  Thread Starter [velocitykendal](https://wordpress.org/support/users/velocitykendal/)
 * (@velocitykendal)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/query-posts-by-title/#post-1795923)
 * Am I missing something here? I had already checked that page in the codex and
   couldn’t see a parameter that I could leverage to query post titles.
 * This is the loop I have nested on the page to call in posts from another post
   type, but at the moment it’s missing an extra parameter to restrict it to posts
   that share the same string in the title as the current page:
 *     ```
       <?php $track_query = new WP_Query( "post_type=tracks" );
          if ( $track_query->have_posts() ) { ?>
               <ul>
               <?php
              	   while ( $track_query->have_posts() ) {
                  $track_query->the_post();
                  // post stuff here
                  } ?>
                </ul>
       <?php } wp_reset_postdata(); ?>
       ```
   
 *  Moderator [t-p](https://wordpress.org/support/users/t-p/)
 * (@t-p)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/query-posts-by-title/#post-1795947)
 * I can,t tell what’s missing. Sorry.
 *  Thread Starter [velocitykendal](https://wordpress.org/support/users/velocitykendal/)
 * (@velocitykendal)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/query-posts-by-title/#post-1795981)
 * Well the first line is only using the post_type parameter. I need it to use this
   AND also constrain the results to a specific title string. E.g.
 *     ```
       $thetitle = the_title();
       $track_query = new WP_Query( "post_type=tracks&post_title=$thetitle" );
       ```
   
 * The thing is, ‘post_title’ isn’t a valid parameter. I was wondering if there’s
   a clever way around this?
 *  [JackdUpFord](https://wordpress.org/support/users/jackdupford/)
 * (@jackdupford)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/query-posts-by-title/#post-1795997)
 * Instead of `$thetitle = the_title();`
 * try
 * `$thetitle = get_the_title();`
 * the_title() has a permalink embedded inside of it, where as get_the_title() is
   just a string.
 *  Thread Starter [velocitykendal](https://wordpress.org/support/users/velocitykendal/)
 * (@velocitykendal)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/query-posts-by-title/#post-1796016)
 * Thanks for the tip JackdUpFord, that’s useful. Unfortunately I still dont have
   a way to plug it into the query…
 *  [evandavidpaul](https://wordpress.org/support/users/evandavidpaul/)
 * (@evandavidpaul)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/query-posts-by-title/#post-1796261)
 * I also need to query by the post title velocity. Have you found any answers yet?

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Query posts by title?’ is closed to new replies.

## Tags

 * [custom post type](https://wordpress.org/support/topic-tag/custom-post-type/)
 * [query](https://wordpress.org/support/topic-tag/query/)
 * [title](https://wordpress.org/support/topic-tag/title/)

 * 7 replies
 * 4 participants
 * Last reply from: [evandavidpaul](https://wordpress.org/support/users/evandavidpaul/)
 * Last activity: [15 years, 5 months ago](https://wordpress.org/support/topic/query-posts-by-title/#post-1796261)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
