Tag Info

New answers tagged

0

Yes, $wpdb->update is sufficient protection. You should not escape or prepare the data. From the documentation of wpdb: data (array) Data to update (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). This means that if you are using GET or POST data you may need to use stripslashes() to ...


1

After experimenting with birgire's comment (huge thanks), I put together a relatively simple regular expression that seems to be solid: SELECT * FROM wp_usermeta WHERE meta_key REGEXP('^wp_([[:digit]]+_)?capabilities$') The prefix can be easily added / changed without breaking the expression. It also requires at least 1 number and an underscore for any ...


2

You could simply use the get_blogs_of_user() function: echo count( get_blogs_of_user( $user_ID ) ); instead of your custom SQL query.


0

Assuming you want to do this for all posts that have the custom_field not empty, add this to your functions.php: add_shortcode('update-posts-from-custom-fields', 'upfc_fields321'); function upfc_fields321() { $args = array( 'meta_key' => 'custom_field', 'meta_query' => array( array( 'key' => ...


0

ok folks, i did it anothere way.. here's how i did it: add_filter( 'pre_get_posts', function( $query ) { if( ! is_main_query() || ! is_post_type_archive() || ! $query->get( 'section', false ) ) return $query; global $wpdb; $section = $query->get( 'section' ); unset( $query->query['section'] ); unset( ...


1

Although this is possible, it really is not viable. I've done a lot of research on this subject, but could not find a straight forward answer I went and had a look at the WP_Query class for a possible solution, and I came to the conclusion that what I was trying to accomplish would not be possible with a simple one or two liner code. PITFALLS To get the ...


0

I recommend backing up the database before making any major/bulk changes to it. First you need to get all users with the role "contributors", then update their roles to "author". $contributors = get_users(array('role'=>'contributor')); foreach($contributors as $contributor){ wp_update_user(array( 'ID' => $contributor->ID, 'role' => ...


0

When I discovered ServerPress to develop local and push WP sites to production, I have not looked back. The time it saves me in both set up of a local WAMP, creating of dev sites, and then loading painlessly the site to a server with a public face is worth every nickel for it. I no longer need to fuss with paths that break when going live, for example. I ...


0

I personally use BackupBuddy (a paid solution, from iThemes.com). For your scenario, you could install it on your local dev machine, and perform the following one-time actions: Add a one-time configuration for your server as a "Remote Destination" (including FTP/sFTP credentials and target directory). Copy an 'importbuddy.php' script to your remote ...


1

You can try this with WP_User_Query instead: $args = array ( 'meta_query' => array( array( 'key' => 'newsletter', 'value' => 'true', ), array( 'key' => 'account', 'value' => 'false', ), ), 'date_query' => array( array( ...


0

Thanks to WordPress 4.1 you can do better for meta_query : https://make.wordpress.org/core/2014/10/20/update-on-query-improvements-in-4-1/ function recherche_avancee( $query ) { if ( !is_admin() && $query->is_search ) { $meta_query = array( 'relation' => 'OR' array( 'relation' => 'OR', ...


0

Here is exmaple code,You will change as per your requirement $wpdb->query( " UPDATE $wpdb->posts SET post_parent = 7 WHERE ID = 15 AND post_status = 'static' " );


1

Wanted to update this code you guys worked on for the wordpress 4.0 and above as esc_sql() is deprecated in 4.0 higher. function title_filter($where, &$wp_query){ global $wpdb; if($search_term = $wp_query->get( 'search_prod_title' )){ /*using the esc_like() in here instead of other esc_sql()*/ $search_term = ...



Top 50 recent answers are included