Tag Info

Hot answers tagged

3

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


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


2

Get all of your posts in one query, then count the iterations of your loop. Pseudo-code follows. if ( $query->have_posts() ) { $i = 0; while ( $query->have_posts() ) { // If $i is 5 (5th post), end one row and start the next if (++$i == 5) { echo '</tr><tr>'; } // the rest of your loop output


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


2

Here is what is happening with your code: query_posts uses the global variable wp_query. It always overwrites that variable, which is why you should not use query_posts pretty much ever. Your first query_posts clobbers the original $wp_query data. You start the Loop The first thing you do in that loop is reset $wp_query to the original query. Now the ...


2

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


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.


1

First of all DO NOT use query_posts(), it will modify your original loop; use WP_Query() instead (Why?). And you can call them as of your need (See here). <?php //Female Query ?> <?php $fmargs = array ( 'tag' => 'female', 'posts_per_page' => -1 ); $female_query = new WP_Query( $fmargs ); while ( $female_query -> have_posts() ): ...


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

Whenever $results_desc->feed_product_desc is empty, the post content is used. Otherwise the content is never used. if (!empty($results_desc->feed_product_desc)){ $content = $results_desc->feed_product_desc; } else { $content = get_the_content(); $content = strip_tags($content); } Whenever the post content is used, all HTML tags are ...


1

I would use a custom query. http://codex.wordpress.org/Custom_Queries#Keyword_Search_in_Plugin_Table This explains how to search for keywords in a custom table. You could adjust this as required to your table and required output.


1

You could do it like this? <table border="5"> <tbody> <tr> <td width="150" colspan="2"> <h4>NLP</h4> </td> </tr> <tr> <td width="50">Overview</td> <td width="100">A natural language processing challenge.</td> </tr> ...


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

to_ping is a list of URLs WordPress should send pingbacks to. pinged is a list of URLs WordPress has sent pingbacks to. Do not use these fields for something else. They are parsed many times in core code (69 matches for to_ping); their format is fixed. You cannot reduce the query load by using these fields, because all post meta fields are fetched in ...


1

dbDelta is extremely picky. Looking at your code I'd say you've violated this rule: You must put each field on its own line in your SQL statement Two of your fields are sharing lines with parenthesis. I haven't tested that particular pattern but dbDelta is extremely picky. I don't know if that space after NOT NULL will matter. I doubt that checking ...


1

You still can use lists - just use proper CSS (every third li - first li in every row - should have clear property set; You can use CSS classes or :nth-child selector to do this). If you really have to use table (I don't suggest it - it's not a very good idea, because it's not semantic), you can do something like this: <table> <?php while ( ...



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