How to fetch records from database WordPress

wpdb is a simple wrapper around the mysql_* functions, but you can’t mix and match them. $wpdb->query does not return the database reference that mysql_fetch_row needs. It … … returns an integer corresponding to the number of rows affected/selected. If there is a MySQL error, the function will return FALSE. (Note: since both 0 and … Read more

Images are not showing after moving WordPress installation from server to localhost?

The tip in Part 2 at the site you link that reads Unzip the database you’ve downloaded and open it with text editor (Notepad++ or Dreamweaver) and use “Find and Replace” option to change “http://olddomain.com” with “http://newdomain.com” and then import it with phpmyadmin. is absolutely wrong. Running a find/replace on a database dump with a … Read more

insert image alongwith with custom data via a frontend form

For Image uploads you can use wp_handle_upload(). Adding attachments can be done through wp_insert_attachment(). The association between attachment and your costing item can be achieved through update_post_meta(). Aside: Meta keys starting with an underscore _ are not showing up in WordPress UI. You code could be looking like this: <?php $my_costing_id; /* contains the id … Read more

Can WP give a value a post ID?

Add a rewrite rule and extra query vars to handle incoming requests, direct the rewrite rule to a single page post type, create a custom page template for that page, then do whatever querying you need using the query vars set by your rewrite rule.

Add field to user meta table in database when link is clicked

Personally, I would store the post IDs (as opposed to URLs). Something like: function wpse_143643_add_user_bookmark() { if ( ! empty( $_GET[‘bookmark’] ) && is_singular() && is_user_logged_in() ) { if ( ! $bookmarks = get_user_meta( $user_id = get_current_user_id(), ‘bookmarks’, true ) ) $bookmarks = array(); $bookmarks[] = get_queried_object_id(); $bookmarks = array_unique( $bookmarks ); update_user_meta( $user_id, ‘bookmarks’, … Read more

Why this query is not showing any result on wordpresss home page?

First of all your query is wrong. The right query is $mypost = $wpdb->query($wpdb->prepare(“SELECT post_content FROM $wpdb->posts WHERE ID = %d”, 2)); Second the $wpdb->query will returns an integer value indicating the number of rows affected/selected. You can check here http://codex.wordpress.org/Class_Reference/wpdb#General_Syntax If you want generic result you can use $wpdb->get_results http://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results $mypost = $wpdb->get_results($wpdb->prepare(“SELECT post_content … Read more