How to change featured content to a different tag in WordPress Twenty Fourteen?

The internal implementation details of that feature are of questionable sanity. If you take a look at said featured-content.php template you would see that it get posts from twentyfourteen_get_featured_posts() however the only thing that function has is twentyfourteen_get_featured_posts filter from quick look at which in peculiar fashion nothing is actually getting hooked because twentyfourteen_setup() declares … Read more

Add value to usermeta without removing previous values?

update_user_meta( int $user_id, string $meta_key, mixed $meta_value, mixed $prev_value=”” ) updates existing user meta based on user_id and meta key. If there are many fields with the same key, you can pass `prev_value’ to tell which field you want to update. add_user_meta( int $user_id, string $meta_key, mixed $meta_value, bool $unique = false ) adds meta … Read more

Execute a shortcode when clicking on a image

It’s certainly possible but you’re probably looking at doing an ajax request on the image click which in turn executes the short code and returns the output. This involves three distinct steps, binding the ajax request to an action, executing the ajax request and handling the response, and actually writing the script that will process … Read more

Automatically check the option “Enable stock management at product level” on product creation

To set default values of a new post, you can try this code : $postType = “product”; add_action(“save_post_” . $postType, function ($post_ID, \WP_Post $post, $update) { if (!$update) { // default values for new products update_post_meta($post->ID, “_manage_stock”, “yes”); update_post_meta($post->ID, “_stock”, 1); return; } // here, operations for updated products }, 10, 3);

Sort posts from multiple sites by date

You could just usort the array before iterating. $allBlogPosts = get_posts( array( ‘posts_per_page’ => -1, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’ )); usort($allBlogPosts, ‘sortPosts’); function sortPosts($a, $b){ return strtotime($a->post_date) – strtotime($b->post_date); } //Your display loop… FYI, if you’re using PHP>=5.3, you can use a closure, which I personally think is cleaner for this type of … Read more

Specified file failed upload test. wp_upload_handle

The error you are seeing is coming from wp_handle_upload(): // A properly uploaded file will pass this test. There should be no reason to override this one. if ( $test_upload && ! @ is_uploaded_file( $file[‘tmp_name’] ) ) return call_user_func($upload_error_handler, $file, __( ‘Specified file failed upload test.’ )); I am not sure about your context, but … Read more

How can I access the “description” of a menu item?

I don’t like the idea to parse the menu items again. As an alternative solution I suggest to store the description during the first run: add_filter( ‘walker_nav_menu_start_el’, ‘wpse_78483_get_current_items_description’, 10, 2 ); /** * Get nav items description. * * @wp-hook walker_nav_menu_start_el * @param string $item_output * @param object $item * @return string */ function wpse_78483_get_current_items_description( … Read more

Run shortcode at certain resolution

Ok, let’s clarify the concept. You don’t want download the content for mobile device, and you want to rely on screen resolution. You know that php (wordpress) run on server, screen resolution is a completely client-side matter. So the flow will be: user send a request to your site your site page load on client … Read more

PHP Script within wordpress theme

PHP does not ever display in source, if things are working correctly. PHP executes on the server. If things are working the way they should you never see the PHP source. I don’t know what your conditions are for this project, but the most straightforward way to access a script is to make a custom … Read more