Tag Info

New answers tagged

0

The best I can find is: $wpdb->show_errors(); $result = $wpdb->get_results("SELECT * FROM this is not a valid query"); $wpdb->hide_errors(); Unfortunately, that hardly solves the problem. I want to handle the error programmatically, not just echo it to the output stream.


1

First, you're using prepare() wrong. Should be this: $wpdb->prepare("SELECT Active FROM testers WHERE user_id = %s", $user_id) If you have any debugging enabled, it will throw an error from your code. Which may make your location header not work properly. Second, the get_var() function indeed returns null when there are no results. Third, setting a ...


-2

have_posts() needs a Wordpress database query before it will show anything, check it here like this: $the_query = new WP_Query( 'post_type=post' ); if ( $the_query->have_posts() ) { echo '<ul>'; while ( $the_query->have_posts() ) { $the_query->the_post(); echo '<li>' . get_the_title() . '</li>'; } ...


0

I will suggest Wordpress Duplicator, It is best tool for copying your site to any other host/localhost, and its free, I have used it many times and it works every-time with different server settings. Please note that I haven't affiliated with it in any way.


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

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

You want the query to look like this: SELECT email FROM wp_my_users WHERE email = 'mail@example.com' instead of this: SELECT email FROM 'wp_my_users' WHERE email = 'mail@example.com' So try to construct your query with: $sql = "SELECT email FROM {$my_table_name} WHERE email = %s"; $result = $wpdb->get_var( $wpdb->prepare( $sql, $email_address ...


2

You will transfer your db a couple of time from and to your live and dev site, so I would suggest downloading and installing a plugin called Velvet Blues Update URL's. This will take care of all the rewriting for you. This is how to use it. Once installed and activated, go to 'Tools >> Update URL's. This will open the following screen In the 'Old URL' ...


0

The question should be how many users can php-mysql stack handle instead of WordPress as WP is developed on those 2 principal technologies. Being said that, if you can configure server with advanced server techniques, host WP in a good managed server, optimized database load and queries then WP can handle as many members as you want. If you install ...


1

The default search is handled by WP_Query mostly by a method called parse_search(), which is triggered by the s parameter. You can search the source of WP_Query for is_search and piece together a few other bits and pieces. Or you can just create a query... $s = new WP_Query(array('s' => 'test')); ... dump the SQL... var_dump($s->request); ... ...


2

Do you have any data showing that user meta won't work? Until you do — don't mess with it. You are not likely to get from-scratch solutions as convenient and more performant without significant effort.


1

Since you mention multiple environments you can manually define the site URL within your wp-config.php file define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/path/to/wordpress'); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/path/to/wordpress'); Keep in mind that it will override what you have set in your options table. As detailed in ...


0

This is what you're looking for: http://codex.wordpress.org/Plugin_API/Action_Reference/init Example from Codex: add_action('init', 'process_post'); function process_post(){ if(isset($_POST['unique_hidden_field'])) { // process $_POST data here } }


0

The "orderby" parameter takes a fallback value, and here you want to get the posts sorted by post date when the vote value is not available. so you can just append "date" to the orderby parameter like below to get the rest of the post in the loop sorted as per the dates:-- 'orderby' => 'meta_value_num date', For more details check the Codex


1

There are several problems with your code. Unless you, or a plugin, has added wp_frm_item_metas to $wpdb, $wpdb has not idea what $wpdb->wp_frm_item_metas is. You will get an "Undefined Property" error, and your query won't work. You can't just use $wpdb-> plus any table name. That won't work. You have to add the property to $wpdb, which isn't that ...


1

In a nutshell there is no generic reliable way to load WordPress core from arbitrary file. Since core and extensions directories are independent from each other (they are co-located by default, not by necessity) only core configuration "knows" where extensions are, but not other way around. In private code things like this just get hardcoded. In public code ...


1

The Transient API saves data inside the database, which isn't as effective as APC, but a similar workflow as used for transients can be used for APC. It is important to check if APC is available and active, so its functions are usable. Because this isn't always the case, it is to consider to add a alternative to APC via Transient API and combine those two ...


1

What you did wrong here was to prepare those items in the first place. You only run "data" variables through prepare(). You don't run table names, or sort directions, or limits through it. These are part of the SQL command itself, they are not data that refers to information which is stored in a column in the database. Your SELECT query has no data ...


0

You can make your script a part of your WordPress post, just use the $wpdb object provided by the WordPress itself. The $wpdb object already has the database connection established and you can use it to perform any database operation: insert, update, query etc... Thisi s preferrable method for doing you DB stuff inside WordPress as you do not have to open ...


6

Don't use settings api for this. Register a custom post type, 'Joke' see register_post_type docs add_action( 'init', function () { $labels = array( 'name' => 'Jokes', 'singular_name' => 'Joke', 'add_new' => 'Add New', 'add_new_item' => 'Add New Joke', 'new_item' => 'New Joke', 'edit_item' => 'Edit Joke', ...


-4

I know this is an old post. However none of these answers are correct, and I wanted to post the solution I used to solve this problem. The best way to set a parent page through all of your posts is through the (Appearance -> Customize) menu. You can set a static page for your home page or posts page. When you set a static post page, that page will be the ...


1

Yes 90-100ms round trip + time to prepare SQL statement + time to execute statement + time to send results back multiplied by the number of times you need to query the database. Sure the connection may stay open but it's an inherently expensive thing to do. Considering that some setups can respond in full in less than 100ms never mind the database ...


0

How I've done it in the end is as follows: Because it's triggered on post_status_transition, each log can be effectively linked to a particular post. Therefore, I can use add/update_post_meta to store the response and timestamp as meta fields for that post. To retrieve all logs, I can simply do: $logs = array(); $query_args = array( ...


0

I am using Wordpress 3.8.1 and I changed line 67 of wp-admin/network/upgrade.php and added , 'sslverify' => false like this: --- a/wp-admin/network/upgrade.php 2014-03-29 14:31:28.081943490 +0100 +++ b/wp-admin/network/upgrade.php 2014-03-29 14:30:52.785947460 +0100 @@ -64,7 +64,7 @@ $upgrade_url = admin_url( ...


2

Creating Tables with plugin This page shows how to work with tables in plugins. Example on that page includes table creation during installation of plugin. But it can be dynamically used also to create table. See below. if(isset($_POST['create']) { $table_name=$_POST['table_name']; Note : don't use - in variable names. global $wpdb; $sql = "CREATE TABLE ...


1

It is not clear exactly what you are doing. For example, I am not sure what the data is that you are saving or where/when it needs to be displayed, but it sounds like you need: The Transients API Or the Options API However, if your data is very complicated you might want a dedicated table. Without more information, that is the best I've got.


2

Since version 3.9 (that will be released soon, actually in beta 2) WordPress will use mysqli to connect to database (3.9- versions use mysql) so you can actually use new wpdb instances and helper function to connect externa values from WordPress. What I suggest is to configure external database using constants in wp-config.php in this way you are sure that ...


0

Did you read this: https://codex.wordpress.org/Custom_Queries I think it will help you understand the basics, then you can take it from there.


2

Add a rewrite rule and extra query vars to handle incoming requests, direct the rewrite rule to a single page post type, create a custom page template for that page, then do whatever querying you need using the query vars set by your rewrite rule.


0

What you should do is to create a CPT as a container for displaying your data. For each of the CPT "posts" store relevant meta data to is required to be able to get the data from the other DB, and create the per CPT themes files which will access the DB and display the data.



Top 50 recent answers are included