Tag Info

Hot answers tagged

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


4

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


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

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

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


2

Globalizing WordPress-defined vars is not the same as creating your own global variables. In the former, you have no choice, it's the latter which you can choose to avoid. Wrap your functions in a class and define your table name as a member var. This lets you define it in one place and keeps it out of the global scope.


2

DBDelta is extremely picky-- to the point of being maddening sometimes. From the Codex: You must put each field on its own line in your SQL statement. You must have two spaces between the words PRIMARY KEY and the definition of your primary key. You must use the key word KEY rather than its synonym INDEX and you must include at least one KEY. You must ...


2

Looking at this article on WP.org it seems you have to create your database first, with some SQL: function mp_install_table() { global $wpdb; $table_name = $wpdb->prefix . "countries"; $sql = "CREATE TABLE $table_name ( id mediumint(9) NOT NULL AUTO_INCREMENT, name tinytext NOT NULL, labour_cost INT, ...


1

You could use a foreach loop - function mp_install_name_data() { global $wpdb; $table_name = $wpdb->prefix . "names"; $rows = array( array( 'id' => '1', 'name' => 'matt', 'age' => '20', 'point_one' => '0.45', 'point_two' => '0.22' ), ...


1

You can't insert more than one row using one call to $wpdb->insert, however you can use $wpdb to perform a raw sql query with $wpdb->query. For MySQL syntax see docs. Remember to use $wpdb->prepare to escape data before inserting. $wpdb->query( $wpdb->prepare( "INSERT INTO $table_name (id, name, age, point_one, point_two) VALUES (%d, ...


1

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


1

These additional dropdowns are added via the restrict_manage_posts action hook. This means the dropdown output isn't filterable, but you can remove the hooked action from Yoast SEO. The filter dropdown is added by the posts_filter_dropdown() method in the WPSEO_Metabox class. It's added in the setup_page_analysis() method of the same class, which is hooked ...


1

Try this code. Create a file like "my_db.php" and paste this code: global $table_version; $table_version = "1.0"; function func_table_contactus(){ creat_table_contactus(); } function creat_table_contactus(){ global $wpdb; global $table_version; $table_contactus = $wpdb->prefix."contactus"; $slider_ver = ...


1

Most of the complex tables in admin are produced using WP_List_Table class. Despite being formally private, it has been widely used by third party extensions for years now. It's not exactly friendly to work with, so you should research it and consider if your requirements merit reusing it or just replicating markup to achieve same visual look.


1

WordPress already has both user and post meta data tables, and associated API for handling the data. Storing an array of post IDs for each user in user meta sounds like it would work for your application.


1

I'm not sure if suggesting plugins here is still taboo, but I'm going to go that route for you, because it's going to be the most effective and simple method for you to achieve this. Install two plugins: Custom Post Type UI, and Advanced Custom Fields Alternatively, forego CPTUI (it's just nice to have a visual) and create a new custom post type via your ...



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