Hot answers tagged

4

You've just discovered an important feature of the core test suite: it forces any tables created during the test to be temporary tables. If you look in the WP_UnitTestCase::setUp() method you'll see that it calls a method called start_transaction(). That start_transaction() method starts a MySQL database transaction: function start_transaction() { ...


3

You pretty much answered it - legacy code. WordPress is the result of years of code evolution, refactoring and (most importantly) multiple developers/coders/authors - whilst they're getting pretty good at enforcing coding standards/consistency, there will always be a trail of the past.


3

You unserialize() it. Be aware that most WordPress functions will automatically unserialize() database content before using it. See, for example, the Used By list for maybe_unserialize(). This is by no mean an exhaustive list, I'm sure. But if you're retrieving data directly from the database -- because there's not a WordPress function to achieve what you ...


3

This is actually not that hard, but you will have to excuse me for keeping it high level because this is just a stupid thing to do as all things which are security by obscurity. All you need to do is write your WPDB driver, which inherits the WPDB class. Place it in /wp-content/db.php file and make sure to initialize the global $wpdb object with your class. ...


2

When I started out with Wordpress I was anti-plugin. I wanted to add everything in my theme's functions.php. When I looked at the bigger picture it began making sense having and leaving some functionalities inside a plugin. There are many write-ups on the subject of what should go into a plugin and what should go into a theme. I, for one, have done one or ...


1

Creating a table for your WordPress database requires a considerable amount of time. Wordpress Codex has an article with a step by step guide on how to do this, which basically consists of creating a plugin and adding the functions to create a table and trigger the function on plugin install. 1. Creating the Tables: Thew function is this one: <?php ...


1

You should avoid adding new tables or customising the existing tables to add fields for users. If you want to store a phone number etc, do it using user meta: add_user_meta( $user_id, 'riccardo_phone_number', '0123-456-7890' ); .... $phone_number = get_user_meta( $user_id ); User meta is a key and a value with a post ID in the database. There is no need ...


1

Look at this code public function column_default( $item, $column_name ) { switch ( $column_name ) { case 'address': case 'city': return $item[ $column_name ]; default: return print_r( $item, true ); //Show the whole array for.... } } Since you are only trying to render user_id , browser and ...


1

You should get total and result array separately. Total is to create the page numbers and result array will give you limited data for each pages. Refer the below code. if (isset($_POST['list_position']) && $_POST['list_position'] != 'Select by Position'){ $list_position= $_POST['list_position']; $totalPosition= $wpdb->get_var("SELECT ...


1

register_activation_hook() only attaches a function to run on activation of your plugin, not on updating. See the docs for full details, particularly this part: 3.1 : This hook is now fired only when the user activates the plugin and not when an automatic plugin update occurs (#14915). Of course, you could force your hook to run by deactivating and re-...


1

My choice would be to use WP_List_Table. If you continue reading the Codex it makes it clear that it is commonly used by third party code. "Someday" it might go away, but I doubt it will happen abruptly (if at all). If it does change, there will probably be a newer solution to replace it. EDIT: Another thought. if you feel really can't use WP_List_Table ...


1

Why not extend WP_List_Table? It creates responsive tables that collapse to an accordion when the table width exceeds the screen size. See Class Reference/WP List Table. You might take a look at the code in this plugin to get started: Custom List Table Example


1

You can use these filters: add_filter( 'request', 'users_orderby_column' ); function users_orderby_column( $vars ) { // Your code goes here }


1

<?php $mydb = new wpdb('uid','passwd','database','localhost'); $mydb->show_errors(); $query = "SELECT DATE_FORMAT(col1, '%d-%b') AS Pdate, DATE_FORMAT(col1, '%Y') AS Pyear, col2, col3, col4, col5 AS fname FROM table ORDER BY col1 DESC LIMIT 50"; $result = $mydb->get_results($query); echo $mydb->num_rows . ' in table '; ?>


1

Heyaa..., I've found a final answer, hufft... Yeah, first I include the necessary classes just like in this thread : Fatal error after 4.4 upgrade class-wp-list-table And second, I added up this line in the display_tablenav method in WP_List_Table class : $this->screen = get_current_screen(); before this line : $this->pagination( $which ); ...


1

When we call get_the_title(), then the post title is taken through the wptexturize() function via the the_title filter: add_filter( 'the_title', 'wptexturize' ); The en-dash and em-dash are replaced with /* translators: en dash */ $en_dash = _x( '&#8211;', 'en dash' ); /* translators: em dash */ $em_dash = _x( '&#8212;', 'em dash' ); A simple ...


1

First of all you are trying to combine both of the tables by post_parent. $wpdb->posts.post_parent = $wpdb->ftcalendar_events.post_parent I guess data in the ftcalendar_events has children of posts table, try $wpdb->posts.ID = $wpdb->ftcalendar_events.post_parent Also you can try joining tables: SELECT * FROM $wpdb->posts JOIN $wpdb-&...


1

can I just create one using PHPMYADMIN ? Yes.You can. And its a shortest way to do it.


1

I didn't do this recently but in 2014, in a few WordPress projects that I need additional tables I used Laravel components. In WordPress, if you want to create your own tables by using wpdb and mysql queries. But with the Laravel database classes I managed to do this much more elegantly. A quick rundown how I do this: (note: At the time, I used Laravel 4 ...



Only top voted, non community-wiki answers of a minimum length are eligible