List of the years with posts presented

Relationship between post and category is not stored in the posts table. You must extend your query for additional tables. By category id: SELECT YEAR(p.post_date) FROM {$wpdb->posts} p JOIN {$wpdb->term_relationships} tr ON tr.object_id = p.id JOIN {$wpdb->term_taxonomy} tt ON tt.term_taxonomy_id = tr.term_taxonomy_id WHERE tt.term_id = 4 AND p.post_status=”publish” AND p.post_type=”post” GROUP BY YEAR(p.post_date) DESC Or … Read more

Syntax for $wpdb->prepare when searching in two columns

The part after WHERE decides which columns are searched. So you need to change it this way: $foods = $wpdb->get_results( $wpdb->prepare( “SELECT id, foodname, namevariations, calories, carbs, fat, protein, sodium FROM foodsTable WHERE namevariations like %1$s OR foodname like %1$s”, ‘%’ . $wpdb->esc_like( $search_text ) . ‘%’ ), ARRAY_A ); Also you were using LIKE … Read more

WP Optimization: Removing Orphaned wp_options (especially the autoload ones)

Do you have access to a SQL client program like phpmyadmin or something similar? If so give this query SELECT option_id, option_name, LENGTH(option_value) FROM wp_options WHERE autoload = ‘yes’ AND option_name NOT LIKE ‘_transient%’ ORDER BY 3 DESC LIMIT 20; You’ll see the top twenty auto loaded options in descending order of length. Eyeball the … Read more

How To Fix WP Query Returns Results But Shouldn’t?

Couple of things to consider here: 1.) Try adding the meta query only if the value is present: $pairedThing = get_field(‘myThing’); $args = [ ‘posts_per_page’ => 2, ‘post_type’ => ‘thing’, ]; if ( ! empty( $pairedThing ) ) { $args[‘meta_key’] = ‘identifier’; $args[‘meta_value’] = $pairedThing; } 2.) Account for posts without the meta-key set: $pairedThing … Read more

Get the most repeated post contents from a search?

The problem with your approach is that post’s content pretty much ignored in WordPress query architecture. It is meant to be textual information, as opposed to technical meta information. You have several options: Try to modify raw SQL of query request through filters, such as posts_where. Assign school name to custom field and use custom … Read more

Order query by meta_value with multiple custom fields

You can use meta_query to get only posts with display_submenuexpositions = true and order them by order_submenuexpositions. $args = array( ‘orderby’ => ‘meta_value’, ‘meta_key’ => ‘order_submenuexpositions’, ‘meta_query’ => array( array( ‘key’ => ‘display_submenuexpositions’, ‘value’ => ‘true’, ‘compare’ => ‘LIKE’ ) ) ); $query_posts( $args );

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