Generating an HTML table from an array based on dynamic key values

Here is the tested solution- // Your sample array $sample_array = array( 0 => array( ‘meta_key’ => ‘cpf_first_name’, ‘meta_value’ => ‘John’ ), 1 => array( ‘meta_key’ => ‘cpf_first_name’, ‘meta_value’ => ‘James’ ), 2 => array( ‘meta_key’ => ‘cpf_first_name’, ‘meta_value’ => ‘Jane’ ), 3 => array( ‘meta_key’ => ‘cpf_gender’, ‘meta_value’ => ‘Male’ ), 4 => array( … Read more

Adding featured for post using database

First of all, never ever use Plain SQL query to WordPress, because it’s too dangerous. Try $wpdb class, if you need to. BTW, adding posts, post description, assigning featured image, etc. there are wrapper functions designated for these particular tasks, like: wp_insert_post() set_post_thumbnail() – for assigning featured images Always, try to consult Codex or Developer … Read more

Select latest 2 articles, but only from given category

Try the below code- SELECT p.*, t.term_id FROM wp_posts p LEFT JOIN wp_term_relationships rel ON rel.object_id = p.ID LEFT JOIN wp_term_taxonomy tax ON tax.term_taxonomy_id = rel.term_taxonomy_id LEFT JOIN wp_terms t ON t.term_id = tax.term_id WHERE tax.taxonomy = ‘category’ AND post_type = “post” AND post_status = “publish” AND t.term_id != 56 ORDER BY ID DESC LIMIT … Read more