WordPress add_query_arg from ajax and make url friendly

This add_query_arg function is add argument after URL you have enter. You have to get pretty URL so add below code in your functions.php file : function custom_rewrite_rule() { add_rewrite_rule(‘^cars/([^/]*)/([^/]*)/?’,’index.php?page_id=PAGE_ID&type=$matches[1]&models=$matches[2]’,’top’); flush_rewrite_rules(); } add_action(‘init’, ‘custom_rewrite_rule’, 10, 0); function custom_rewrite_tag() { add_rewrite_tag(‘%type%’, ‘([^&]+)’); add_rewrite_tag(‘%models%’, ‘([^&]+)’); } add_action(‘init’, ‘custom_rewrite_tag’, 10, 0); add_action( ‘wp_ajax_get_prepare_link’, ‘prepare_link’); add_action( ‘wp_ajax_nopriv_get_prepare_link’, ‘prepare_link’); function … Read more

Order posts by tags count?

As @Robert hue says you can’t do it directly, you need a filter and a CASE in the orderby eg $args1 = array ( ‘orderby’ => ‘tag_count’, ‘order’ => ‘DESC’, ‘post_type’ => ‘post’, ‘pagination’ => true, ‘posts_per_page’ => ‘1’, // 1 post per page?! ‘meta_key’ => ‘_thumbnail_id’, ‘suppress_filters’ => false, ); function wpse173949_posts_clauses( $pieces, $query … Read more

How to get meta key list efficiently?

As mentioned in the comments you can query the postmeta table directly: public function get_metadata_keys(){ global $wpdb; $meta_query = $wpdb->get_results( ” SELECT DISTINCT meta_key FROM {$wpdb->postmeta} ” , ARRAY_A ); $meta_keys = wp_list_pluck( $meta_query, ‘meta_key’ ); return $meta_keys; } This will return the list of all meta_keys associated to any post.

Display posts from today and future in Elementor ‘posts widget’

Here is the working solution: add_action( ‘elementor/query/my-custom-query’, function( $query ) { $meta_query = $query->get( ‘meta_query’ ); $query->set( ‘date_query’, array( array( ‘after’ => date(‘l, F jS, Y’, strtotime(‘+0 day’)), ) ) ); } ); You can change the strtotime (+1 day….+n day ….-n day) to fetch the event’s date you’re looking for. The date format here … Read more

SQL query to list all posts of specific post type with a specific set of associated postmeta values as a column

Using built-in WP functions to get the data is usually a better approach. It can be more performant, and is preferable security-wise because you’re using prebuilt queries instead of building your own. In a plugin, you can use something like: <?php // Get all published CPTs $allEvents = get_posts(array( ‘post_type’ => ‘ajde_events’, ‘post_status’ => ‘publish’, … Read more