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 8480761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:22:59+00:00 2026-06-10T19:22:59+00:00

I created two different custom post types: Videos and Locations. I then created a

  • 0

I created two different custom post types: “Videos” and “Locations.”
I then created a custom taxonomy called “Video_Categories.”
I have assigned this custom taxonomy to both of the custom post types.

What I want to do is display the Videos that have the same terms as one another on the Locations.

For example:

Video posts:

  • Name: Video 1; Video_Category: Brisbane, Queensland;
  • Name: Video 2; Video_Category: Gold Coast, Queensland;
  • Name: Video 3; Video_Category: Sunshine Coast, Queensland;

Location post:

  • Name: Brisbane; Video_Category: Brisbane;

I want to create a query from the Location page that looks at the taxonomy of this post and returns the video posts that have the same taxonomy.

In the above example, the “Video 1” video post would be returned and displayed on the location page.

  • 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-10T19:23:00+00:00Added an answer on June 10, 2026 at 7:23 pm

    Good question, this is a little bit different than getting related categories or tags, though still uses a similar premise. There are a few ways you can do this, but one of the easiest may be to use a custom function that utilizes WP_Query. Add the following code to your functions.php file.

    // Create a query for the custom taxonomy
    function related_posts_by_taxonomy( $post_id, $taxonomy, $args=array() ) {
        $query = new WP_Query();
        $terms = wp_get_object_terms( $post_id, $taxonomy );
    
        // Make sure we have terms from the current post
        if ( count( $terms ) ) {
            $post_ids = get_objects_in_term( $terms[0]->term_id, $taxonomy );
            $post = get_post( $post_id );
            $post_type = get_post_type( $post );
    
            // Only search for the custom taxonomy on whichever post_type
            // we AREN'T currently on
            // This refers to the custom post_types you created so
            // make sure they are spelled/capitalized correctly
            if ( strcasecmp($post_type, 'locations') == 0 ) {
                $type = 'videos';
            } else {
                $type = 'locations';
            }
    
            $args = wp_parse_args( $args, array(
                    'post_type' => $type,
                    'post__in' => $post_ids,
                    'taxonomy' => $taxonomy,
                    'term' => $terms[0]->slug,
                ) );
            $query = new WP_Query( $args );
        }
    
        // Return our results in query form
        return $query;
    }
    

    Obviously you can change anything in this function to get the exact results you are looking for. Have a look at http://codex.wordpress.org/Class_Reference/WP_Query for further reference.

    With that in place, you now have access to the related_posts_by_taxonomy() function, where you can pass in whichever taxonomy you want to find related posts for. So in your single.php or whichever template is being used for your custom post types, you can do something like the following:

    <h4>Related Posts</h3>
    <ul>
    <?php $related =  related_posts_by_taxonomy( $post->ID, 'Video_Categories' );
        while ( $related->have_posts() ): $related->the_post(); ?>
            <li><?php the_title(); ?></li>
        <?php endwhile; ?>
    </ul>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using SQL Server 2008 R2. I have created two different databases Master
I have two list of different objects : List<Report> List<Newsletter> each having a 'created
I created two custom JQuery UI widgets with same name but with different namespaces
I've created a custom tab activity which has two different drawables for portrait and
I've created a custom button in my Android app that has basically two different
I have a requirement to create two different maps in C++. The Key is
I have two different .Net projects, hosted on github. I would like to create
I have created a UITableView that is of type UITableViewStyleGrouped . I have then
I have a class called RunningInteger , which -- on a different thread (to
In my application, I have two lists of sounds from different categories and a

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.