Upload image to wordpress

Output during saving You can not print something during the data is saved. If you use die( var_dump( $your_var ) ); it will print the values, but also stops the script. The reason is, first the data will be parsed. Then you will be redirected back to profile.php. So everything you print while parsing the … Read more

Delete old post with new post

If i understand the question correctly, you want that whenever a user adds a new post, all his/her previous posts should be deleted. I wonder why would you do that!! 🙂 But anyway, you can use this code. add_action(‘save_post’, ‘delete_prev_posts_by_user’, 10, 2 ); function delete_prev_posts_by_user( $post_id, $post ){ if( ‘publish’ == $post->post_status ){ $the_special_category_id = … Read more

Import data from arbitrary CSV to WPAlchemy meta fields

Here’s a piece of code similar to what I have used to fix the problem once imported the data: <?php define(‘MY_METABOX_ID’, ‘my_metabox_id’); define(‘MY_METABOX_PREFIX’, ‘my_metabox_prefix_’); define(‘MY_CUSTOM_POST_TYPE’, ‘my_custom_post_type’); // Include WordPress define(‘WP_USE_THEMES’, false); define(‘WP_DEBUG’, 1); require_once(‘../wp-load.php’); // extract all MY_CUSTOM_POST_TYPE posts $q = new WP_Query(‘post_type=” . MY_CUSTOM_POST_TYPE . “&nopaging=true’); // for each post while($q->have_posts()) { $q->next_post(); $p … Read more

Form fields based on custom fields

Our solution to this was to use Formidable Pro and the following setup. //************************************************** // Generate the contest form //************************************************** // Determin if radio or not add_filter(‘frm_field_type’, ‘change_my_field_type’, 10, 2); function change_my_field_type($type, $field){ global $post; if($field->id == 8){ if (get_post_meta($post->ID, ‘_cmeta_contest_q1_type’, true) !== ‘field’) { $type=”radio”; //change field to radio on multi-answer questions } else … Read more

How to add a prefix to existing custom fields over MYSQL query?

important: backup your database first! Assuming your table prefix is ‘wp_’, this query will change the custom field names: update wp_postmeta set meta_key = ‘booking_testfield’ where meta_key = ‘testfield’; NB: this also assumes that the custom field name is unique to your application, i.e. it isn’t used by another post type. If it is possible … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)