Reputation: 203
if been searching for hours :-( Hope anyone can help me.
I'm in a custom post type called "grhdogs". There I need to fetch the current page title of that page and search with that title in another custom post type called "slideshow" and echo (as string) the page ID of the matching pagetitle in "slideshow".
The background is that in both custom post types are always matching page titles. I have to bring them together because "grhdogs" is a post and "slideshow" is the matching slideshow that I want to display in the post.
Upvotes: 1
Views: 5951
Reputation: 8819
You can try some thing like this.
<?php
//get the current title of the page
$postTitle = get_the_title();
//search for similer post in db table
$postID = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type='slideshow' AND post_title = %s",$postTitle));
//print id
echo $postID;
//or use get_post($post_id) to get whatever you want
$getCustomPost = get_post($postID);
echo $getCustomPost->id;
?>
Upvotes: 1