get post id using the $query_vars variable

When viewing a single post, get_the_ID(); used within the loop will return the current post’s ID. But I don’t have a reference page that has the list of $query_vars params… Dumping it global $wp_query; var_dump($wp_query->query_vars); would provide such a reference. Where you’d subsequently see that $wp_query->query_vars[‘page_id’] yields the page ID.

The use of including upgrade.php when building custom queries

No, and in fact you should not include the wp-admin/includes/upgrade.php file in a plugin. There is no real valid use case for doing so. It doesn’t do anything for you or add any useful functions for a plugin. As for your question, you say “it doesn’t work” but you fail to define what that means. … Read more

$args numberposts variable

Yes, there is no way to get screen size with PHP, because it runs on server, while the screen is something related to client (browser). However, in OP you say: for a desktop visitor I show 10 posts and for a mobile visitor I show 3 posts and even if you can’t get the screen … Read more

Sorting Grids with Essential Grid and Events Manger

After researching this quite a bit I managed to sort the Events Manager events by date in the Essential Grid plugin. If you started with the solution above, you can delete the added parameters field under source tab of Essential Grids, it’s not needed anymore. So here’s what I have in functions.php. Note: I have … Read more

Get posts by category with pure SQL query

If you want to be able to get the category by name, this should work: SELECT DISTINCT substr(post_title, – instr(reverse(post_title), “https://wordpress.stackexchange.com/”) + 1) AS year FROM {$wpdb->posts} p LEFT JOIN {$wpdb->term_relationships} rel ON rel.object_id = p.ID LEFT JOIN {$wpdb->term_taxonomy} tax ON tax.term_taxonomy_id = rel.term_taxonomy_id LEFT JOIN {$wpdb->terms} t ON t.term_id = tax.term_id WHERE post_status=”publish” AND … Read more

Get IDs of posts currently visible on archive

When the wp_enqueue_scripts action fires, the main query has already run and the posts are in the global $wp_query. We just need to grab the ID from each object in $wp_query->posts, the wp_list_pluck function makes that easy: function wpd_get_post_ids(){ if( is_archive() ){ global $wp_query; $post_ids = wp_list_pluck( $wp_query->posts, ‘ID’ ); // $post_ids now contains an … Read more

Possible to get posts from multiple meta keys/values in a single query?

An easy query like the following should work for you: <?php $_query = new WP_Query( array( ‘post_type’ => ‘post’, ‘posts_per_page’ => -1, ‘post_status’ => ‘publish’, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘key1’ ), array( ‘key’ => ‘key2’ ), ), ) ); ?> Note the ‘relation’=>’OR’ in meta_query. More at: WP_Query – Custom … Read more

cron job to auto delete posts of a specific post type older than x days

// add the schedule event if it has been removed if( ! wp_next_scheduled( ‘mg_remove_old_entries’ ) ) { wp_schedule_event( time(), ‘daily’, ‘mg_remove_old_entries’ ); //run the event daily } // action hooked to fired with wordpress cron job add_action( ‘mg_remove_old_entries’, ‘mg_remove_old_entries’ ); function mg_remove_old_entries() { $posts = get_posts( [ ‘numberposts’ => -1, ‘post_type’ => ‘vfb_entry’, ‘date_query’ => … Read more

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