WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Trashing Posts does not Remove from Database (6 posts)

  1. rugbert
    Member
    Posted 4 years ago #

    So Ive almost completed this project. Im using custom fields, and a custom search (wpdb) to deal with my posts.

    My problem, and this is huge, is that when I go to manage my posts and hit trash, they still exist in the DB.

    So my custom search and the way I display my posts (modified search, Im filtering based on a custom field and putting the results in tables) doesnt work because the stuff I trash STILL shows up :/

    here is my code:

    for($t=1; $t<=2; $t++){
    $postids=$wpdb->get_col($wpdb->prepare("
    SELECT DISTINCT post_id
    FROM   wp_postmeta
    WHERE  post_id IN (SELECT post_id
    	   FROM   wp_postmeta
    	   WHERE  ( meta_key = 'Bedrooms'
    				AND meta_value = '$t' ))
    AND post_id IN (SELECT post_id
    		   FROM   wp_postmeta
    		   WHERE  ( meta_key = 'Active'
    					AND meta_value = 'Yes' ))
    AND post_id IN (SELECT post_id
    		   FROM   wp_postmeta
    		   WHERE  ( meta_key = 'listType'
    					AND meta_value = 'Rental' ))
    ",$t)); ?>
    <table class="myTable">
    <thead>
    <tr>
    <th><?php echo($t.' Bedrooms'); ?></th>
    <th>Price</th>
    <th>Available</th>
    </tr>
    </thead>
    <?php
    $tr = 0;
    if (!empty($postids)) {
    foreach ($postids as $id) {
    $tr++;
    if($tr%2){$trClass="dark";}else{$trClass="light";}
    $post=get_post(intval($id));
    setup_postdata($post);
    $utilities = get('Utilities');
    ?>
    <tr class="<?php echo ($trClass); ?>">
    <td class="address"><a href="<?php the_permalink(); ?>"><?php
    echo get('Address');
    ?></a>
    </td>
    <td class="price"><a href="<?php the_permalink(); ?>"><?php
    echo ('$'. get('Price'));
    ?></td></a>
    <td class="date"><a href="<?php the_permalink(); ?>"><?php
    echo get('Availability');
    ?></td></a>
    </tr>
    <?php
    }
    } wp_reset_query();
    ?>
    </table>
    
    <?php
    }
    ?>
  2. rugbert
    Member
    Posted 4 years ago #

    I guess this part of the loop:

    <?php if (have_posts()) : ?>
          <?php while (have_posts()) : the_post(); ?>

    is what properly pulls active posts from the db? I just used the standard loop and my the post I deleted didnt appear. But as soon as I used my custom search again its there.

    HELP!

  3. Trash is actually a holding status. The post is removed from view, but it remains in the database for 30 days unless removed manually. When viewing the list of posts in the admin panel, click the "Trash" link near the top and either select "Delete Permanently" underneath the post or hit the "Empty Trash" button.

    http://codex.wordpress.org/Trash_status

  4. Darrell Schauss
    Member
    Posted 4 years ago #

    It looks like your are basing what posts you want to pull off of the posts meta. You will probably want to INNER JOIN the wp_posts table against the wp_postmeta so you can filter with a WHERE clause as post_status = 'publish' select only postmeta from what are published posts.

    Something like this. (Not tested)

    SELECT DISTINCT wp_postmeta.post_id
    FROM wp_postmeta
    INNER JOIN wp_posts
    ON wp_postmeta.post_id=wp_posts.post_id
    WHERE wp_postmeta.post_id IN (SELECT post_id
    	   FROM   wp_postmeta
    	   WHERE  ( meta_key = 'Bedrooms'
    				AND meta_value = '$t' ))
    AND wp_postmeta.post_id IN (SELECT post_id
    		   FROM   wp_postmeta
    		   WHERE  ( meta_key = 'Active'
    					AND meta_value = 'Yes' ))
    AND wp_postmeta.post_id IN (SELECT post_id
    		   FROM   wp_postmeta
    		   WHERE  ( meta_key = 'listType'
    					AND meta_value = 'Rental' ))
    AND wp_posts.post_status = 'publish'
  5. rugbert
    Member
    Posted 4 years ago #

    it actually kills the query :/ Im not very good at SQL yet but I love your solution, can you help me with it?

  6. rugbert
    Member
    Posted 4 years ago #

    nvm, I got it. wp_posts doesnt have a column called post_id, its called ID

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.