get_posts output always same post

This is because you are not passing the parameters in the correct way, taxonomy param needs to be passed under tax_query. Please replace the $args with the below:– $args = array( ‘posts_per_page’ => 4, ‘tax_query’ => array( array( ‘taxonomy’ => ‘tag’, ‘field’ => ‘slug’, ‘terms’ => ‘pp’ ) ) ); For more details check the … Read more

get_posts ignoring ‘category’ and displaying all posts

Ok. After a frustrating weekend I have a workaround (but still not real reason why the simpler version worked on one install and not another!) $args = array( ‘posts_per_page’ => $pageSize, ‘offset’=> $offset, ‘tax_query’ => array( array( ‘taxonomy’ => ‘category’, ‘field’ => ‘term_id’, ‘terms’ => 9 ) ); While this is a totally workable solution, … Read more

Auto-change Post Status on First Page Load

If you want the default post status to be in-progress when contributors click on “New Post”, then you can try the following: /** * Set default post status as ‘in-progress’ for contributors * * @link https://wordpress.stackexchange.com/a/143128/26350 * * @param array $data * @return array $data */ function wpse_143100_wp_insert_post_data( $data ) { $current_user = wp_get_current_user(); if( … Read more

get_posts showing only 5 posts. (nopaging and posts_per_page -1 not working)

The ‘posts_per_page’ => -1, and ‘nopaging’ => true, shouldn’t be in your tax_query params. That might be what’s throwing it off. Try: $args = array( ‘post_type’=>’gpp_prod’, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’, ‘posts_per_page’ => -1, ‘nopaging’ => true, ); and: $args[‘tax_query’] = array( array( ‘taxonomy’ => ‘cat_prod’, ‘field’ => ‘term_id’, ‘terms’ => $category ) );

Get posts in between specific ID’s

You can simply just use the post__in parameter inside your query arguments or inside your pre_get_posts action EXAMPLE (Adjust as necessary. Code requires at least PHP 5.4+ due to short array syntax ([])) $args = [ ‘post__in’ => range( 10, 15 ), ]; $q = get_posts( $args ); var_dump( $q );

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