How to update all posts but the current one (post__not_in not working?)

There’s a more elegant way of updating your posts using the global $wpdb. function rsc_unpublish_all_ads( $post_id, $post, $update ) { // select all ads other than the current one $args = array( ‘nopaging’ => true, ‘post__not_in’ => array($post_id), ‘post_type’ => ‘rsc-ads’, ‘post_status’ => ‘publish’, ‘fields’=>’ids’ ); $query = new WP_Query($args); $published_ads = $query->posts;//array of post … Read more

Get posts inside Get terms problem

When you do the following in your code $posttags = get_the_tags($item->term_id);, $item is referring to a post object, not a term object. Therefore, term_id is an invalid property. This should be throwing a PHP notice. While not certain, I think what you are intending to do is: $posttags = get_the_tags($item->ID); since get_the_tags takes a post … Read more

get_posts() doesn’t consider user permissions

Use is_user_logged_in you code may like $posts_array = get_posts( array( ‘post_type’ => ‘download’, ‘post_status’ => ‘publish’ ) ); //$posts_array = apply_filters( ‘downloads_shortcode’, $posts_array ); foreach($posts_array as $post) { setup_postdata($post); if ( is_user_logged_in() ){ $title = “<a href=”https://wordpress.stackexchange.com/questions/100335/. get_permalink( $post->ID ) .”>” . $post->post_title . “</a>”; echo $title; } else{ // do something } } Note:If … Read more

I don’t arrive to do order_by title when i have a conditionnal year in a request

I tried your code and is working fine for me $args = array( ‘post_type’ => ‘project’,’posts_per_page’ => -1,’year’ => date(‘Y’) – 2, ‘orderby’=> ‘title’,’order’ => ‘ASC’); $myposts = get_posts( $args ); The thing is as you can see he is only fetching the posts from 2015. If you don’t have any posts with the publish … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)