Articles of database

WordPress database becoming huge. How to analyze and optimize it? fear of running out of memory

look at the size of my wordpress database tables: are there simple ways to optimize it? I fear of running out of memory one day maybe bad collation? how can I analyze what is eating up so much space in the posts and post meta tables?

WordPress Database Charset/Collate

Is there an easy way of getting the charset and collation of the DB tables in WordPress without resorting to SQL queries?

Usage of Direct Database Call Without Caching Error

I have a custom function that creates a dynamic copyright year range based on the year of the first and last posts in the database: function jldc_copyright_dates() { global $wpdb; $copyright_dates = $wpdb->get_results( ” SELECT YEAR(min(post_date_gmt)) as firstdate, YEAR(max(post_date_gmt)) as lastdate FROM $wpdb->posts ” ); if ( $copyright_dates ) { $copyright_year = $copyright_dates[0]->firstdate; if ( […]

Corrupt WordPress Database

The weirdest WordPress problem ever I think. A clients site with a large database of posts has got a mind of it’s own. One minute everything seems fine, the next posts, categories and tags are missing. At the minute the dashboard is telling me there’s 2309 posts in 9 categories but when I click the […]

WP database error for comments_popup_link()

I’m using the comments_popup_link() function to show the number of comments for each post in a loop. <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php if ( get_post_meta($post->ID, ‘thumb_value’, true) ) : ?> //something <?php else: ?> //something else <?php endif; ?> <h2><a href=”<?php the_permalink() ?>” title=”<?php the_title(); ?>” rel=”bookmark”><?php the_title(); ?></a></h2> <?php […]

How to increase the character limit for post name of 200?

I have post name in Thai which uses UTF-8 character. Many of them encode into super long in ASCII e.g. วิธีการหลีกเลี่ยงข้อผิดพลาดทั้ง-8-ในชีวิตการแต่งงาน I’ve changed the type of “post_name” using phpMyAdmin to VARCHAR(1000) and collation to utf8_unicode_ci. However, in my WordPress backend editor, the above post name is still automatically cut to วิธีการหลีกเลี่ยงข้อผิ when I try to […]

Filter WordPress posts by between parameter

How to filter WordPress posts by a taxonomy and between parameter? Consider a mobile website with “memory size” taxonomy, I need to show posts that have more than 256 mb memory and less than 768 mb. Is it possible through WP_Query class or “posts_where” filter? I know that post_meta is better for this purpose, but […]

Safe way to find last inserted id in a table?

Is it safe to use $wpdb->insert_id; to find the id of a last updated row id just after an update? ex: $sql = $wpdb->insert($table_name, $arrayWithDataToInsert, array(‘%s’,’%s’)); $results[‘new_created_id’] = $wpdb->insert_id; or am I running into the possibility that I will catch the id of another row that was inserted immediatly after mine? Thanks!

Database sync between local and production

I was watching Mark Jaquith’s presentation at WCSF 2013 recently and in the Q&A Mark mentioned something about rsync – after a quick Google I can see this is done via SSH – my question is this: is this something that can be done to a local development environment? Do you still need to copy […]

How to correctly add a table to the WordPress MySQL database

I want to add a new table to the WordPress database. I need this one for a specific section of my WordPress website, that requires something a bit different than what I can achieve through custom posts. What would be the correct approach to do that? Is it enough to just add a table of […]