Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9229843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:40:23+00:00 2026-06-18T05:40:23+00:00

I am currently using a custom query to grab related posts. However I was

  • 0

I am currently using a custom query to grab related posts. However I was curious if there is a way to not grab the current post I am currently on. My only thought is to use the ID of the post and exclude it somehow. Is this possible?

Here is my current code pulling related posts:

// Get The Related Term
$terms = array();
foreach(wp_get_object_terms($post->ID, 'series') as $term){
    $terms[] = $term->slug;
};

// Grab The First Term From The Array
$related_term = array_shift(array_values($terms));

// Query The Related Posts
$related_posts = $wpdb->get_results( 
    "
    SELECT * 
    FROM $wpdb->posts
    LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
    LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    LEFT JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)
    WHERE $wpdb->posts.post_type = 'sermon' 
    AND $wpdb->posts.post_status = 'publish'
    AND $wpdb->term_taxonomy.taxonomy = 'series'
    AND $wpdb->terms.slug = '$related_term'
    ORDER BY $wpdb->posts.post_date DESC
    "
);
foreach ($related_posts as $related) {
    echo '<li><a href="'.get_permalink($related->ID).'">'.get_the_title($related->ID).'</a></li>';
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:40:24+00:00Added an answer on June 18, 2026 at 5:40 am

    You can use the not equal clause <> in the where query. Something like

    AND $wpdb->posts.ID <> $post->ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a wordpress/mysql set up using the 'custom post type' which currently holds
I am currently working on android project where I am using a custom list
I am currently ordering a list of custom objects using the IQueryable OrderBy method
I want to add traffic information to my custom map. Currently I'm using a
I am using wordpress latest version. Currently my blog is set to custom permalink
In Mule, currently I am using a custom transformer JavaObjectToJSON (as a Response Transformer)
Currently I am using a DLL Library to get lists of custom objects. Which
Our current project does not use Hibernate (for various reasons) and we are using
I'm currently developing a form on salesforce.com using an apex form with a custom
I have a query where I am only interested in the row count, however

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.