Hot answers tagged

11

It's not mandatory per se, but you should always use that and should consider it as mandatory. Consider the scenario when two Wordpress site has been setup in the same database. One with prefix wp_ and another with wp2_. If you install your plugin in both of the sites with the prefix, you created database will be wp_liveshoutbox for first site and ...


9

This is how I would update a field named 'Address': function updateAddress() { global $current_user; get_currentuserinfo(); $newAddress = '123 New Street'; xprofile_set_field_data('Address', $current_user->id, $newAddress); }


7

The details of custom post types aren't stored anywhere, they're loaded at runtime with each request via register_post_type calls.


6

I am not going to give any specific code but I will give you Idea how it can be done without creating any custom database table. I am assuming one driver per truck Algorithm Create two html list, make them sortable. Each list items represents a post type and have ID data field. Once sorting is done get all ids in order. Make two array one contains truck ...


5

As the article mentions, using wp_options is not a good idea when you have thousands of terms, mainly because there's: a lot of serialization involved OR long option names (the limit is 64 characters) In this particular case, yes, it's appropriate to create some custom tables. To save time, you can use this plugin (update more recently than Simple Term ...


5

A convenient way to use $wpdb in plugins, with custom tables and custom functions is write a class or a couple of functions that get the wp object, and configure it. An example: /* Return global wpdb aready setup with custom tables */ my_plugin_get_db( wpdb $wpdb = NULL ) { static $db; if ( is_null($db) || ! is_null( $wpdb ) ) { $db = is_null($wpdb)...


4

Ok, first of all, I feel like an idiot, although in my defense most of the articles that talk about this don't mention a very crutial detail in making this work. The answer is that you need to set permission for at least one admin in the database. This info can be found in the Codex here: http://codex.wordpress.org/Editing_wp-config.php#...


4

I think your question is a perfect example for the XY Problem. In WordPress you do not create such a menu in a post editor. You use a menu. Once you start thinking about your problem from this point, everything is easy. :) First register a custom navigation menu for this list in your theme’s functions.php: add_action( 'wp_loaded', '...


4

Consider the following: Your plugin is used on a wordpress network, which uses different table prefixes for each site. Your plugin could be running simultaneously on 836 different sites, all in the same database. wp_385677_liveshoutbox is a perfectly reasonable table name. Your plugin is installed by a user who has some concept of security, and has changed ...


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

I finally found the custom post type data. It is stored in the wp_post table where post_type = custom post type (e.g. "products"). The field (column) data is stored in wp_postmeta where the meta_key is the column name and meta_value is the column value. This query will bring back all data associated with the custom post type "products": SELECT P.ID, P....


3

Please take a look at user_register hook This is fired when a new user is registered and conveniently passes you the user ID of the new user. function function_name( $user_id ) { /* do what you want to do with ID here */ } add_action( 'user_register', 'function_name');


3

If you want do what the TablePress author recommended, you'd need first to create a custom page (or post category) template - see Codex for Page_Templates - I wouldn't explained it better then there. :) There you'd need to create a custom WP_Query, or get_posts() / get_pages() query to get the list of posts or pages that you need (you will have to provide ...


3

This can be used, mainly by plugins, to add some additional information to a comment. By having one generic table you don't need to add columns to wp_comment for every additional piece of data. E.g. a plugin could add a rating to each comment and store that value in wp_commentmeta.


3

That table is essentially the same as for all of the other "meta" tables in the WordPress architecture. It holds misc. bits of extra, usually optional, information about the associated post, user, or in this case comment. You can store whatever information you need to add to a comment-- perhaps a plugin wants to implement "abuse" flags, or comment upvotes. ...


3

While I am a big fan of tweaking wordpress as much as it could because it allows us to, I think the best way forward is to have the best algorithm before coding. Reading your question, I came across " Actually, I have created two custom post type named 'truck' and 'drivers' ". Issue: Linking two post types requires extra work as you are doing because ...


3

Your dot and quote notation is funky. Try this: if($wpdb->get_var("SHOW TABLES LIKE '$table_name'" ) != $table_name){ $sql= "CREATE TABLE $table_name ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30) NOT NULL, lastname VARCHAR(30) NOT NULL, email VARCHAR(50), reg_date ...


3

There is error in sql query. You have defined time as datetime and default value mentioned in current_timestamp. Define time as timestamp. Also specify length of email and page fields. Corrected query: $sql = "CREATE TABLE " . $table_name . " ( id INT NOT NULL AUTO_INCREMENT, time TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, //Change datetime to ...


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

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. ...


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 ...


2

The prepare() method escapes %s. The second piece of code you listed breaks because quotation marks are added to the table name, hence it doesn't match what's in the DB. The first piece of code works because it's a straight string replacement hence matching the name of the table in the database. What is the error message you are getting? HTH


2

WP-Table Reloaded is a great plugin which allows you to create tables and use their shortcodes in your post. Bear in mind, however, that not all themes are "table-friendly". Alternatively, you can try Dean's FCKeditor Plugin For WordPress, which appears to have an "Insert Table" function to keep you from messing around with HTML. And the best option, in my ...


2

This plugin does allow theming. Check out the "Other Notes" tab in the plugin page. As far as making it sortable, your path of least resistance is to use javascript. Here's a jQuery plugin that will do (almost) all the work for you. Hope that helps! Cheers~


2

The code you posted doesn't work because there is no global $currentpage. There are $current_screen and $pagenow. add_action( 'pre_get_posts', 'wpse_63414_hide_pages' ); function wpse_63414_hide_pages( $query ) { if( !is_admin() ) return $query; global $pagenow; $pages = array('2','26'); if( 'edit.php' == $pagenow ...


2

You can use the function get_post_types to get information on any and all post types that are active at that time. To get info on a specific post type, use get_post_type_object.


2

Write a function that uses $wpdb->prefix as a fallback. Something like this: function wpse65880_table_with_prefix($table) { // should define array in config file, rather than hard coding $my_tables = array("table1", "table2", "table3", "table4"); if (in_array($table, $my_tables)) { // "qa_" should also be a config file setting ...


2

Suggested here by JLeuse. It seems the contents within WP Table Reloaded is indeed separated from the post, which means the default Wordpress search function won't be able to fetch it...


2

$wpdb is outside the scope of your plugin file, you need global $wpdb; before using $wpdb->prefix


2

SELECT * FROM wp_posts, wp_2_posts, wp_3_posts WHERE wp_posts.post_content LIKE '%foo' OR wp_2_posts.post_content LIKE '%foo' OR wp_3_posts.post_content LIKE '%foo'; should do the trick. (Note that in Multisite, there shouldn't be a wp_1_posts -- your root site uses wp_posts etc.)



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