Using wp_handle_upload() to Direct Specific Path by Using $overrides

You need to specify a list of allowed mime types. You could make it easy by just getting the allowed mime types like: $file = $_FILES[‘the-file’]; $upload_file = wp_handle_upload($file, array( ‘test_form’ => false, ‘mimes’ => get_allowed_mime_types() )); If you look at the codex for Default allowed mime types, you could manually specify which ever mime … Read more

Inserting above the comment template

It mainly depends on a theme, whether there is a hook, in which you can call an action. Simple ways, how to do that: You insert your code directly into single.php, right above the code calling comments_template(), You create a hook (e.g. above comments_template()) as do_action(‘my_hook’) and then you hook into it your function add_action(‘my_hook’, … Read more

Problem only while using require_once() within functions.php

I noticed the URL of the custom Dashboard page is this… themes.php?page=functions-test.php Notice how the page is the name of my external functions in includes/functions-test.php. The problem is in this line, the one that refreshes the page just before the permission error… echo ‘<meta http-equiv=”refresh” content=”0;url=themes.php?page=functions.php&saved=true”>’; Now it seems so obvious. Look at the page … Read more

new_to_publish fires multiple times

OK! found how to – there is 2 little information about how to attach a function to a status change but this hook does the job and does it well. function miniupdate_webnews( $new_status, $old_status, $post ) { if ( $old_status == ‘draft’ && $new_status == ‘publish’ ) { // YOUR FUNCTION HERE… } } add_action( … Read more

Posts are duplicating on wp_post_update

Ah, I found the answer myself. I’ve added global $post before the loop and now all seems to works fine. I don’t know if this is a good practice, so if you have another ideas share them 🙂 Here is the revised code: add_action(‘save_post’, ‘bulk_refresh’); function bulk_refresh($post_id) { if($post_id != 123)//123 is the ‘certain page’ … Read more

Injecting a custom sql query into a page/theme

The hooks you are looking for can be found in the WordPress Codex WP_Query – Filters: Filters posts_distinct – Alters SQL ‘DISTINCTROW’ clause to the query that returns the post array. posts_groupby – Alters SQL ‘GROUP BY’ clause of the query that returns the post array. posts_join – Alters SQL ‘JOIN’ clause of the query … Read more