Tag Info

Hot answers tagged

3

I think instead of using PHP rand you're better off limiting ( if you need to ) using posts_per_page and then getting a random set using orderby => 'rand'. Full List of Ordering Parameters So if I were to edit your query it would look like this: $args = array( 'post_type' => 'attachment', 'meta_key' => 'on_front_page', 'meta_value' ...


2

You can achieve this with the date_query parameters added in version 3.7. To modify the main query on your posts page before it is run and apply the date_query parameters, we use the pre_get_posts action: function historical_posts_list( $query ){ if( $query->is_home() && $query->is_main_query() ){ $date_query = array( ...


2

All of these hooks are called in a similar fashion and get passes similar data. Under normal circumstances there should be no meaningful performance difference between them. One scenario I can think of is that if you aren't properly targeting your code to specific queries and it runs in every query then posts_search might fire less time, because other two ...


1

Use a custom table. Create it as a network table, and store the site ID, so you can use just one table for the whole network. row_id | site_id | post_id | user_id There is no equivalent for such a table in the current core tables. Avoid serialized data, because that format is PHP specific, so you cannot read its data in any other language (including ...


1

Here's a hack for the main post query in wp-admin that should do the trick: /** * Modification of the wp-admin main (post) query: * If current user has the "client" role then * show client's posts OR posts where the "client" meta value is the client id. * * @see http://wordpress.stackexchange.com/a/173967/26350 */ function ...


1

If you go the Category route, you could do something like this: First, get a slug of today's date: $date_slug = current_time('M-d'); Then, create a taxonomy query argument array: $tax_query = array( array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => $date_slug, ) ); Then, build a query using ...


1

$q = new \WP_Query([ 'monthnum' => date('n'), // beware the date function! 'day' => date('j'), ]); while ($q->have_posts()) { $q->the_post(); // ... } wp_reset_query(); See the documentation on date parameters. Since you want to modify the home page query specifically, you might hook into pre_get_posts and modify the main query ...


1

Maybe you have an image that was smaller or equal to the thumbnail size, if so, then no thumbnail will be created, and this.data[i].sizes.thumbnail will be undefined.



Only top voted, non community-wiki answers of a minimum length are eligible