querying user bookmarks from a large number of bookmarks

It looks like the default get_bookmarks() http://codex.wordpress.org/Function_Reference/get_bookmarks is using this query: SELECT * FROM wp_links WHERE 1=1 AND link_visible=”Y” ORDER BY link_name ASC; You can check the function in /wp-includes/bookmark.php. The get_bookmarks() function has limit and order parameters that you might find helpful. The option get_bookmarks(“limit=5”) gives this query: SELECT * FROM wp_links WHERE 1=1 … Read more

Database create or redirect

Not having cPanel doesn’t mean you can’t create a database, but if you are trying to install WordPress on a server without a database server, that is your biggest problem. I would consider other hosting. Your questions in order: cPanel is a convenience. So are Plesk and other similar pieces of software. If you have … Read more

Fetch a single row from a custom table for to a given ID

$wpdb->wp_philosophy_philosopher won’t work here because it has not been defined. $wpdb->table_name works only with default tables. You can create your own using: $wpdb->philosophy_philosopher = $wpdb->prefix . “philosophy_philosopher”; Note that the wp_ is just the table prefix and has been omitted here because different installations can have different prefixes and that your code stop to work … Read more

making php value numeric

Your question is more about SQL than WordPress. If you want to sort your term names as numbers, you can in general try SELECT * FROM wp_terms ORDER BY name+0 ASC or SELECT * FROM wp_terms ORDER BY name*1 ASC or use CAST: SELECT * FROM wp_terms ORDER BY CAST(name AS SIGNED) ASC where you … Read more

Second ezSQL initialization for MSSQL

I apologize for the late reply, I was transferred to a new project and forgot about it. I ended up using a standard PHP PDO connection. Here is an example: // connection variables $servername = “localhost”; $database = “database”; $user = “username”; $pass = “password”; try { //create connection $DBH = new PDO(‘sqlsrv:Server=”.$servername.”;Database=”.$database, $user, $pass); … Read more

select a single val though a table in wordpress

Use the method get_var() instead. I’ve also tidied up your code (if you’re gonna use double quotes, take advantage of them!) & added data escaping with the handy prepare() method. global $wpdb; $cat_id = $wpdb->get_var( $wpdb->prepare( “SELECT category_id FROM {$wpdb->prefix}awpcp_categories WHERE category_name = %s”, $ad_cat ) );

What could cause a WP Option to get truncated?

It was a 👼 character. Make sure you sanitize everything that gets written as field values, even if it’s a username. trim(preg_replace(“/[^\w\s]+/”, “”, $user->full_name)) I assumed there are no special characters in Instagram usernames. Never assume. I don’t really use Instagram, just my plugin supports it. BTW it got truncated on the first occurrence of … Read more

WordPress Mysql query and Duplicate

There’s no need for custom SQL here, use the power of meta queries: $posts = get_posts( array( ‘posts_per_page’ => -1, ‘meta_query’ => array( array( ‘key’ => ‘Country’, ‘value’ => ‘UK’, ), ), ) ); foreach ( $posts as $post ) $cities[] = get_post_meta( $post->ID, ‘city’, true ); foreach ( array_unique( $cities ) as $city ) … Read more