Ordering posts in get_posts

You can set the orderby to post__in. Here is a superior post loop: $args = [ ‘post__in’ => [ 1, 2, 3, 4 ], ‘orderby’ => ‘post__in’, ]; $q = new \WP_Query( $args ); if ( $q->have_posts() ) { while ( $q->have_posts() ) { $q->the_post(); ?> <article id=”post-<?php the_ID(); ?>” <?php post_class(); ?>> <?php the_title(); … Read more

Show Only Posts Owned By Logged In User + my post

First, I second Q Studio comment: check Tom McFarlin’s post with a warning about using pre_get_posts. More specifically, pre_get_posts works everywhere, including RSS and dashboard, and you might want to exclude your logic from such places. That said, if I understood correctly what you are trying to do, you can achieve it by using author__in … Read more

Get posts for which a custom field is not present, with get_posts

You could use NOT EXISTS as the value for comparem, you could also check for empty value if thats relevant This code only checks if hidden meta does not exists $postsForSitemap = get_posts([ ‘numberposts’ => -1, ‘orderby’ => ‘modified’, ‘post_type’ => [‘post’, ‘page’], ‘order’ => ‘DESC’, ‘meta_key’ => ‘hidden’, ‘meta_compare’ => ‘NOT EXISTS’ ]; This … Read more

Automatically republish old posts

http://wordpress.org/extend/plugins/oldest-2-newest-redux/ it takes your oldest post and reposts it in the front every 24 hours, but you can change the hours on the php file in the plugin folder not sure if this is what u are looking for.

Can I use numberposts=-1 and offset together when using get_posts()?

I believe the issue is that the underlying MySQL query requires a LIMIT clause to go with the OFFSET clause. (I tried to verify this about MySQL and found this https://stackoverflow.com/questions/255517/mysql-offset-infinite-rows ). Since MySQL can’t accept those parameters (offset without a limit), WordPress seems to drop the offset argument. It’s still a little hacky, but … Read more

how to exclude “featured” posts from the main loop?

This would be an appropriate use of query_posts(), with a post custom meta query. Since you’re querying by meta_key=featured_article&meta_value=on, you would then exclude on the same parameters. <?php // Setup the custom meta-query args $exclude_featured_args = array( ‘meta_query’ => array( array( ‘key’ => ‘featured_article’, ‘value’ => ‘on’, ‘compare’ => ‘!=’ ) ) ); // globalize … Read more

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