Create new database through static page code

DBDelta is extremely picky— to the point of being maddening sometimes. From the Codex: You must put each field on its own line in your SQL statement. You must have two spaces between the words PRIMARY KEY and the definition of your primary key. You must use the key word KEY rather than its synonym … 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

Displaying post excerpt using wpdb query

I guess your post_excerpt field is empty and you need to generate an excerpt from the post_content. I agree with @t f using the general WP_Query(), have_post(), the_post(), the_excerpt() method of looping. I just want to mention that WordPress comes with the handy wp_trim_words() function that can be used to shorten text strings. Outside the … Read more

how to get db values without using an loop with wpdb->get_results()

You want get_row. Per the Codex: Get all the information about Link 10. $mylink = $wpdb->get_row(“SELECT * FROM $wpdb->links WHERE link_id = 10”); The properties of the $mylink object are the column names of the result from the SQL query (in this example all the columns from the $wpdb->links table, but you could also query … Read more

How do I count columns on a custom WPDB query?

Under straight mysql core functions you would use mysql_num_fields, but through $wpdb (wordpress database object), I found the following worked for me. $result = $wpdb->get_results(‘DESCRIBE ‘.$table,ARRAY_A); $columns = array(); foreach($result as $row) { $columns[] = $row[‘Field’]; } $num_fields = count($columns);

Custom SQL Query passing array to WHERE p.id

This is more of a SQL question then a WordPress question. Here are some ideas: You’re most likely looking for this kind of structure: AND p.ID NOT IN (1433, 1344) You should consider using $wp->prepare() if your query depends on some user input. You might also want to replace CURDATE() with a PHP generated date … Read more

Active DB queries in WordPress?

wpdb doesn’t include such kind of API, mostly since it descended from ezSQL which didn’t either (as far as I remember). While there are some helpers for insert/update stuff, most of query abstraction happens in WP_Query since that’s where bulk of complicated querying is typically going on.

Can’t update multiple rows with $wpdb query

$wpdb->query() returns number of rows affected by the query. It’s returning NULL indicates that there is an error in your query. The problem with your query is that you are updating $wpdb->posts table, but the condition depends on $wpdb->postmeta table. You have to join these tables for the query to work. Another problem is that … Read more

List of ways to access WordPress database?

There’s some overlap, but each isn’t an abstraction of the previous, and there are definitely some things you don’t want to do outside of the API. Most things, actually! WP_Query is for retrieving posts and pages, it doesn’t update anything, and it doesn’t fetch data that isn’t a post or page. The higher level API … Read more

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