mysql query from wordpress page using custom table

I think if you add a couple of periods before and after the php variable in your query, remove the use of mysql_fetch_array, and use get_row(), it should work better. Here’s how I would get a park from your custom table: <?php $page_title = wp_title(”); $park = $wpdb->get_row(“SELECT * FROM $wpdb->park_data WHERE park_name=””.$page_title.”””); if($park) { … Read more

Handling large N data in WordPress

Custom table(s). WordPress posts are not structurally a fit for what you are doing. Trying to use them for this will result in a lot of unnecessary data processing and storage. But you need to think through your own database design and you need to be good with SQL or you will end up inefficient … Read more

Delete all one-word comments

DISCLAIMER : Not a WordPress Developer, Just a MySQL DBA If you have privileges to login to MySQL and query data you could collect all the comment_ID values that have one word. SELECT comment_ID FROM wp_comments WHERE REPLACE(TRIM(comment_content),’ ‘,”)=TRIM(comment_content); You can test this by also seeing the comment_content SELECT comment_ID,comment_content FROM wp_comments WHERE REPLACE(TRIM(comment_content),’ ‘,”)=TRIM(comment_content); … Read more

Custom MySQL Query with logic

Thank’s everyone for your attention. If anybody will need to query database with two postmeta, here is the code SELECT p.* , CASE WHEN m1.meta_value=0 OR m1.meta_value IS NULL THEN m2.meta_value ELSE m1.meta_value END meta_value FROM aka_v_posts p LEFT JOIN aka_v_postmeta m1 ON p.id=m1.post_id AND m1.meta_key=’_wpsc_special_price’ LEFT JOIN aka_v_postmeta m2 ON p.id=m2.post_id AND m2.meta_key=’_wpsc_price’ WHERE … Read more

Pushing stored procedure to a multisite database in WordPress

Here are the Steps: STEP 01 : Put code in a Text File Open up a text editor (vi, nano, emacs) and place your code in it. Save it as /tmp/mynewcode.sql STEP 02 : Collect All Databases Names MYSQLCONN=`-uroot -ppassword` SQLSTMT=”SELECT schema_name FROM information_schema.schemata” SQLSTMT=”${SQLSTMT} WHERE schema_name NOT IN” SQLSTMT=”${SQLSTMT} (‘information_schema’,’performance_schema’,’mysql’)” mysql ${MYSQLCONN} -ANe”${SQLSTMT}” > … Read more

Mysql query and order meta value

While the WPDB class, or its global $wpdb instance are your friend when it comes to querying custom tables or WP core data that does not have a higher-level API, it is overkill to use it to query posts. Instead, read up on WP_Query. In your case, you’d use it like so: $args = array( … Read more