Loops Wordpress without repeating the post

Asked

Viewed 154 times

-2

Staff would like to know if anyone here can help me with a query post or loop in wordpress.

So... I insert with wp_insert and I don’t know why it doubles (maybe in the double mouse click) when sending via form.

My question and the next.... even with duplicate wordpress post I would like to not display have my template I will post below I wonder if anyone can help me modify and display without duplicating ?

Since now I thank my friends !

<?php
$args = array(
  'post_type' => 'arquivos',


  );
?>
<?php $the_query = new WP_Query( $args ); ?>
<?php if ($the_query->have_posts()): while ($the_query->have_posts()) : $the_query->the_post();?>
 

 
<?php the_title ();?>
 
<?php endwhile; else:?>
<?php endif;?>

  • There is no way you can dynamically avoid the appearance of duplicate posts. Ideal is that you deal with the problem of inserting twice in the database.

  • Thank you very much friend I’ll try !

1 answer

0

As said the Hegon Felipe, the ideal is to treat the same duplication problem.

Below is a solution for didactic purposes only (it removes from the loop, posts with the same title):

Edit 1: Remove posts with meta_key Name blank.

<?php
    global $wpdb, $table_prefix;
    $arquivos = $wpdb->get_results( '
        SELECT *
        FROM '.$table_prefix.'posts
        LEFT JOIN
            '.$table_prefix.'postmeta
            ON '.$table_prefix.'postmeta.post_id = '.$table_prefix.'posts.ID
            AND '.$table_prefix.'postmeta.meta_key = "Nome"
        WHERE
            '.$table_prefix.'posts.post_type = "arquivos"
            AND '.$table_prefix.'posts.post_status = "publish"
            AND '.$table_prefix.'postmeta.meta_value != ""
        GROUP BY '.$table_prefix.'posts.post_title
    ' );
?>
<?php foreach ( $arquivos as $key => $value ): ?>
    <?php echo $value->post_title ?>
<?php endforeach ?>
  • Friendlier is just one more question as it would look with this condition example ta 'key' = 'Name', 'value' = array ( '' ), 'compare' = 'IN'

  • Besides not duplicating I would like you to compare the custom key field and the values

  • I changed the code, I’d be more or less like that up there.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.