Detect featured image among the attached images

I use the following code to extract the attached images from a post with ID: $args = array( ‘post_type’ => ‘attachment’, ‘post_parent’ => $product_id, ‘post_mime_type’ => ‘image’, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’, ‘numberposts’ => -1 ); $attachments = get_posts($args); The problem is that the above code return all the attached files. Is there a … Read more

WordPress get pagination on wpdb get_results

How do I gee the numbered pagination of custom wpdb result? below code will show one latest post from each authors in the site. I want to show 20 posts per page with a numbered pagination. $postids = $wpdb->get_results( ” SELECT a.ID, a.post_title, a.post_author, a.post_date FROM $wpdb->posts a JOIN ( SELECT max(post_date) post_date, post_author FROM … Read more

What’s the proper way to use a custom table? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago. Improve this question I manually added a table to my wordpress database using sql using CREATE TABLE. I … Read more

How To Get Some Data From WordPress Database Using WordPress $wpdb Query?

I am trying to get some data from WordPress database tables in a plugin. For that, I am using the below code… global $wpdb; $findID = $wpdb->get_var(“SELECT ID FROM wp_posts WHERE post_name=”hello-world””); echo $findID; But it not giving me the post ID in echo? Is there anything wrong…??? 2 Answers 2 Just to clarify the … Read more

Quotes in table name

Since WP3.5, prepare() accepts placeholders as a security measure, instead of just appending the argument to the query. Therefore, $wpdb->prefix needs to become a second parameter, called by %s: $count = $wpdb->get_var( $wpdb->prepare( “SELECT COUNT(id) FROM %s WHERE answer !=’ ‘”, $wpdb->prefix . “faq_questions” ) ); However, doing that returns the table name in quotes: … Read more

How to email user after inserting the username in database in WordPress

I have following piece of code, which inserts usernames and other details of users in the database. After inserting the usernames I want to email them using wp_mail();. I am unable to do so. How can I do this? $member_details->user_login = array_map( ‘sanitize_text_field’, $_POST[‘user_login’] ); $member_details->user_role = array_map( ‘sanitize_text_field’, $_POST[‘user_role’] ); $member_details->status = array_map( ‘sanitize_text_field’, … Read more

How do I batch create revisions of all posts?

I cleaned up an old-site from pasted tags, manually created lists, etc, and I’d like to keep the old posts as “revisions”, so we can easily “compare” with the old posts and retrieve/revert the original content if needed. So I should either injecting the revision rows in the new DB or just naturally create them … Read more