Are there any best practices for creating a Like/Favourite feature in WordPress using custom MySQL tables and without any plugins?

Using WordPress’s wp_postmeta will help you a lot, instead of creating a new table. Functions like get_post_meta(), update_post_meta(), add_post_meta() etc, are readily available for use. All you need is to create a meta_key (which in this case will be wp_likes) and the meta_value (number of likes will be stored), which can be easily retrieved using … Read more

Query not returning child posts for any parent post ID

It seems the problem is that for parent/child relationships, I’m using the Toolset Types plugin, which stores the relationships as fields rather than how WordPress normally thinks of them. This means that when WordPress looks at a post ID, it doesn’t see the child relationships that the plugin does. To get around this, I used … Read more

WP search exclude last letter from string

You can use the get_search_query filter. function mySearchFunction($search_term){ $search_term = substr($search_term, 0, -1); return $search_term; } add_filter(‘get_search_query’,’mySearchFunction’); EDIT Action to filter query results: function mySearchFilterFunction($query) { if ( !is_admin() && $query->is_main_query() && $query->is_search) { $search_term = $query->get(‘s’); $query->set(‘s’, substr($search_term, 0, -1)); } } add_action( ‘pre_get_posts’, ‘mySearchFilterFunction’); get_search_query filter is not needed because it uses get_query_var( … Read more

Category_in return empty

You can achieve that using the tax_query, see the example in the code below: $args = array( ‘posts_per_page’ => 10, ‘post_type’ => ‘product’, ‘post_status’ => ‘publish’, ‘tax_query’ => array( ‘taxonomy’ => ‘the_taxonomy_slug’, //the slug of the taxonomy you want to get ‘field’ => ‘term_id’, ‘terms’ => $categories ) ); See reference in the Codex

Attachment page tag queries & posts not found

That page isn’t a 404, it’s returning a status code 200. The title and body tags also indicate that the page is loading just fine. A couple of things- there is no taxonomy argument. It would be redundant anyway, since the query already contains the queried taxonomy and term pulled from the parsed URL. Your … Read more

How to get all images in Media Gallery with pagination?

EDIT: I didn’t read your code properly, sorry! You’re using get posts which will only retrieve posts. To get all the images from the media library you’ll need to use WP_query. $query_images_args = array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ =>’image’, ‘post_status’ => ‘inherit’, ‘posts_per_page’ => -1, ); $query_images = new WP_Query( $query_images_args ); $images = array(); … Read more

implementing my wp_query using $wpdb class

You haven’t mentioned what you want from this request and what is it for. You should clarify that to get the most accurate answer. Anyway, if you want to write a pure SQL request you can’t use WP_Query but need to use $wpdb->get_results instead, as mentionned by @hadimahoor. Here is a request to get a … Read more

Wpdb->last_query returns bad query

get_users() is a convenience wrapper around WP_User_Query. Maybe you can use that directly, e.g. $user_search = new WP_User_Query( array( ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘meta_key’ => ‘last_login’, //’meta_value’ => ‘DATE_SUB(NOW(),INTERVAL 7 DAY)’, ‘meta_value’ => date(‘Y-m-d H:i’, strtotime(‘-7 days’)), ‘meta_compare’ => ‘<=’, ‘type’ => ‘DATE’, ), array( ‘meta_key’ => ’email_not_logged’, ‘meta_compare’ => ‘NOT EXISTS’, … Read more

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