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

  • Home
  • SEARCH
  • 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 6886097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:43:01+00:00 2026-05-27T05:43:01+00:00

Can someone tell me how to modify the code below so that it filters

  • 0

Can someone tell me how to modify the code below so that it filters out revisions? I tried using revision deletion plugins but they only work for revisions of posts or pages… not custom post types.

<?php

global $wpdb;
global $post;

$review_id = $post->ID;

if (get_post_type($review_id) == "features") {
   $assoc_id = get_post_meta($review_id, "associated_hosts_value", true);
  $review_id = intval($assoc_id);
}

$assoc = $wpdb->get_col("SELECT DISTINCT post_id from wp_postmeta WHERE (meta_key='associated_hosts_value') AND ((meta_value LIKE ',{$review_id},%') OR (meta_value LIKE '%,{$review_id},%') OR (meta_value = '{$review_id}') OR (meta_value LIKE '%,{$review_id}'));");
  • 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-05-27T05:43:02+00:00Added an answer on May 27, 2026 at 5:43 am

    Revision is stored in wp_posts under the post_type column, so you will need to inner join on wp_posts and query for a post_type NOT IN ('revision'):

    "SELECT DISTINCT post_id from {$wpdb->postmeta} INNER JOIN {$wpdb->posts} ON ID = post_id WHERE post_type NOT IN ('revision') ..."
    

    By the way, inserting raw SQL queries in to get_col is a bad practice, as it leaves you vulnerable to SQL injections. Use $wpdb->prepare() as shown here:

    http://codex.wordpress.org/Class_Reference/wpdb#Protect_Queries_Against_SQL_Injection_Attacks

    Note that you will need to escape the % used in the LIKE statements by changing them to %% to work within prepare().

    Also, you shouldn’t hard code WP table names in to your query statements. The wpdb class stores table names for use in constructing your queries, i.e. $wpdb->posts, $wpdb->postmeta. Using these assures that your plugin will always query the correct WP tables. Try your code in a multi site installation to find out why this is important.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone tell me how i can change the .xml file that a flash
Can someone tell me how to change directories using FtpWebRequest? This seems like it
Can someone tell me what the code equivelant in VB.Net to this C# code
Can someone tell me where the code for $file_list is sourced in Virtuemart? To
Can someone tell me what exactly is that about? I have table and inside
Can someone tell me what exactly is that about? I have table and inside
can someone tell me what the difference between assigning event handlers using bind(): $(function
Could someone tell me how I can modify the html before I insert it
Can someone tell me if this is valid code: get { return string.IsNullOrEmpty(TopicID) ?
Can someone tell me the different between LinkButton.PostBackUrl and HyperLink.NavigateUrl? I've got a asp.net

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.