Hot answers tagged

7

The Bad News: The core open source base of Wordpress does make quite a few assumptions about being run on a single server (wp-content, user uploads and media library to name a few) The Good News: Pretty much all cloud providers (including Azure) have abstractions that allow you to work around these design limitations. Fundamentally, you'll be addressing ...


6

For the permanent solution, your SQL query is slightly off - you need: UPDATE db1357924680.wp_posts SET post_content = REPLACE( post_content, '[print_me]', '' ) WHERE post_content LIKE '%[print_me]%' MySQL replace example


5

You might be a little confused as to the purpose and function of nonces in WordPress. Recommended reading: WordPress Nonces An Introduction to WordPress Nonces with Examples Protect_Queries_Against_SQL_Injection_Attacks A nonce is a "number used once" to help protect URLs and forms from certain types of misuse, malicious or otherwise. Nonces help ...


4

First of all, the prefix is only a configuration option and not a security feature. The reason is that once an attacker has access to your database, he can find out any exisiting table prefix within seconds. There's no way this obscurity protects you from any attack. For the prefix itself, WordPress asks you to use only digits, letters (here only basic ...


4

WordPress does not support MySQL 4 : To run WordPress your host just needs a couple of things: MySQL version 5.0 or greater (recommended: MySQL 5.5 or greater) https://wordpress.org/about/requirements/ While the utf8mb4 encoding is recent change and you might work around it, overall you still need compatible MySQL version.


4

Questions like this usually yield a lot of discussions, but let me give it a shot: If you're talking about SQL queries: If you're only adding content, managing plugins, themes and WordPress updates, there's a 99.9% chance that you will never need to write a single line of it. I don't want to put 100% only for cosmetics :) If you are developing (or just ...


4

The problem If the table already exists your code will still try to execute the following queries: 1) ALTER TABLE wp_voicemail_call CHANGE COLUMN user_id user_id BIGINT(9) UNSIGNED NOT NULL 2) ALTER TABLE wp_voicemail_call CHANGE COLUMN call_id call_id BIGINT(9) UNSIGNED NOT NULL 3) ALTER TABLE wp_voicemail_call CHANGE COLUMN opened opened BOOL DEFAULT 0 ...


4

There is an easier way to do this: add_filter( 'the_content', 'my_post_content_remove_shortcodes', 0 ); function my_post_content_remove_shortcodes( $content ) { /* Create an array of all the shortcode tags. */ $shortcode_tags = array( 'shortcode_1', 'shortcode_2', 'shortcode_3' ); /* Loop through the shortcodes and ...


3

You should'nt really be using wp query here, use get_user_meta(); Example: $first_name = get_user_meta(2, 'first_name', true);


3

Here's one experimental idea: Assume we got: post A with the custom field location1 as UK - London post B with the custom field location2 as France - Paris post C with the custom field location3 as USA - New York Then we could use, for example: $args = [ 'meta_query' => [ 'relation' => 'OR', [ 'key' ...


2

You can use plugins such as BackupBuddy, but I prefer to script this and use wp-cli, which reads wp-config.php and means you don't have to worry about mysql credentials. wp-cli allows you to: export the db: wp db export <filename> import the db: wp db import <filename> safe search and replace (including serialised data): wp search-replace <...


2

Try this, should get you started.. (not tested though) function count_total_vote() { $args = array( 'post_type' => 'post', // Your post type 'status' => 'publish', 'meta_key' => 'vote', // Meta Key ); $total = 0; $votes = new WP_Query( $args ); if ( $votes->have_posts() ) { while ( $...


2

If we check how the wp_options table is created (in 4.4) from the schema.php file, we will find the following: CREATE TABLE $wpdb->options ( option_id bigint(20) unsigned NOT NULL auto_increment, option_name varchar(191) NOT NULL default '', option_value longtext NOT NULL, autoload varchar(20) NOT NULL default 'yes', PRIMARY KEY (option_id), ...


2

The post content field is MySQL type longtext, which has a limit of 4 gigabytes. What you may be encountering is an issue with the TinyMCE editor. Content is processed and validated in the browser with JavaScript. If that's the case, I doubt you will improve your situation by using Drupal, since you will be using some sort of JavaScript-driven editor in ...


2

add this in your arguments 'query_id' => 'authors_with_posts', $user_args = array( 'role' => 'frontend_vendor', 'orderby' => 'display_name', 'query_id' => 'authors_with_posts', 'order' => 'ASC', 'number' => $no, 'offset' => $offset );


2

You probably haven't changed the display name, which is probably what is being displayed. "nicename" is used for the author's posts page url and not for display. UPDATE wp_users SET display_name = replace(display_name, @old_user, @new_user);


2

The wp_options table holds a lot of information, whether you deem it important or not really depends on what plugins and information you have set up on your website and how important your website is to you. For example as you've noticed it can hold the information for your active plugins, if you activate an important plugin and then rollback to a database ...


2

Android Push Notification requires you to have GCM Keys and Project ID which needs to be registered on Google Developer console. I am assuming you are able to get your users registration IDs and stored in a table. To send Android Push Notification create a function somewhere in your functions file function AndroidPushNotification($registration_ids, $...


2

cracks knuckles Alright -- so first thing is first. Working w/ WordPress Databases Read this: https://codex.wordpress.org/Class_Reference/wpdb Avoid write SQL statements outside of the $wpdb object. Avoid writing SQL statements like wp_users instead do this: $users = $wpdb->get_results( "SELECT FROM $wpdb->users" ); This will help if you ever ...


2

SQL-wise, you only need to join to the wp_posts table once. Joining to the terms stuff will give you multiple rows, so it's probably easiest to group these and then use GROUP_CONCAT() to flatten the terms into a comma-separated string (updated to use LEFT joins): global $wpdb; $sql = $wpdb->prepare( 'SELECT p.ID, p.post_title AS Product, pm1....


2

Fixed query select p.ID as order_id, p.post_date, i.order_item_name, max( CASE WHEN im.meta_key = '_product_id' and i.order_item_id = im.order_item_id THEN im.meta_value END ) as Prod_ID from wp_posts as p, wp_postmeta as pm, wp_woocommerce_order_items as i, wp_woocommerce_order_itemmeta ...


2

To start with, you need to fix the define of CSV_PATH: define('CSV_PATH',dirname(__FILE__)); as without that, $handle will be false - no file opened or data read. ...then before you run it take another look becaue $col4 and $col5 are not set anywhere either...


2

Try this SQL query: UPDATE wp_terms SET name=LOWER(name);


2

Use the add_args parameter to add an array of query string arguments to pagination links: echo paginate_links( array( 'base' => add_query_arg( 'cpage', '%#%' ), 'format' => '', 'prev_text' => __('&laquo;'), 'next_text' => __('&raquo;'), 'total' => ceil($total / $items_per_page), 'current' => $page, '...


2

It's Simple. Step 1: Create a replica of the instance. Step 2: Import the old .sql file which contained one day lost orders data. Step 3: Use https://wordpress.org/plugins/woocommerce-simply-order-export/ plugin and export CSV or XML of 1 day data which you have lost. Step 4: Install the above plugin in the LIVE instance and import the CSV or XML ...


2

Your wp_comments table already has a comment with id "1". You will need to remove the existing entries. If you want to keep them, then remove the "id" field from all comments you're importing.


2

The direct answer to the question "Is there a way to get 3+ dimensional array from a single MySql command" would be yes, sort of - WordPress routinely stores and retrieves multidimensional data from MySQL rows by serialize()ing and unserialize()ing structured data to/from a string format, so it's certainly possible using WordPress's database interaction ...


2

You should use $wpdb->prepare for queries, as it does all the sanitizing and escaping for you. Also, key is reserved as a field name in MySQL: function ch_details_from_id($id) { global $wpdb; // or try using " . $wpdb->prefix . "ch_guests $query = "SELECT * FROM $wpdb->ch_guests WHERE guest = %d"; $details = $wpdb->get_results( $...


2

No, wpdb::delete does not handle anything other than WHERE field = X. You can just use the query method instead: $ids = implode( ',', array_map( 'absint', $ids ) ); $wpdb->query( "DELETE FROM table_name WHERE ID IN($ids)" );


2

By default, WordPress uses $wp_object_cache which is an instance of WP_Object_Cache to save on trips to the database. Trace back username_exists() function, you will notice that get_user_by() uses WP_User::get_data_by() which return user data from $wp_object_cache immediately without checking if that user exists in database. Note that $wp_object_cache is ...



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