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

Get 2 meta values from meta key column

Not tested 100% but this might work: SELECT a.post_title, m1.meta_value AS SKU, m2.meta_value AS PRICE FROM wp_posts a LEFT JOIN wp_postmeta m1 ON a.ID = m1.post_id LEFT JOIN wp_postmeta m2 ON a.ID = m2.post_id WHERE a.post_type=”product” AND m1.meta_key=’_sku’ AND m2.meta_key=’_price’ Note that _price field corresponds to the “sale price” (if existing) so you may grab … Read more

Prevent versioning for .woff (font) files

If you load your fonts using standard stylesheet enqueueing then you can add this to your functions.php file: function remove_querystrings( $src ) { $parts = explode( ‘.woff?ver’, $src ); return $parts[0]; } add_filter( ‘style_loader_src’, ‘remove_querystrings’, 15, 1 ); I haven’t tested this but I’m fairly certain it will only work if you’re adding the fonts … Read more

Question about of query

The Answer is: Nothing. These two snippets SHOULD return the same posts. However, there are a lot of things, that can change a query before it is executed: plugins, your own theme by a pre_get_posts Filter. So to check if it is an error in this code or some other code, you can disable all … Read more

SEO friendly query vars

At the end I made this work by using Javascript: var currentURL = window.location.href; var prettyURL = currentURL.replace(‘?’, ”).replace(‘state=”, “‘).replace(‘&type=”, “https://wordpress.stackexchange.com/”); window.history.replaceState({}, document.title, “https://wordpress.stackexchange.com/” + prettyURL);

Displaying data from custom table

OK, so maybe the above wasn’t worded very well? I have since made some progress as follows: global $wpdb; $current_user = wp_get_current_user(); $uid = $current_user->ID; $fname = $current_user->first_name . ” ” . $current_user->last_name; $email = $current_user->user_email; $studentTable = $wpdb->prefix.’um_metadata’; $result = $wpdb->get_results ( “SELECT * FROM $studentTable WHERE `user_id` = $uid AND ‘um_key’ = ‘student_number’ … Read more

WordPress query: merge meta key (number) values and sort

I think this is the syntax you are after: $args = [ ‘posts_per_page’ => 5, ‘post_type’ => ‘post’, ‘meta_query’ => [ ‘relation’ => ‘OR’, ‘rating_au_clause’ => [ ‘key’ => ‘rating_au’, ‘compare’ => ‘EXISTS’ ], ‘rating_overall_clause’ => [ ‘key’ => ‘rating_overall’, ‘compare’ => ‘EXISTS’ ] ], ‘orderby’ => [ ‘rating_au_clause’ => ‘ASC’, ‘rating_overall_clause’ => ‘DESC’, ], … Read more

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