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

Plugin.php: PHP Notice: Undefined offset: 0 in

Some code on your site registers a filter or an action with invalid arguments. The errors you see happen, because add_action() or add_filter() was called with a second argument that is not a string, an object or an array. Examples: add_action( ‘wp_head’, NULL ); add_filter( ‘the_content’, -1 ); Disable all plugins, switch to Twenty Eleven, … 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

Activate different theme for temporary preview

You can Detect Server Remote Address and if it matches with your IP then you can use different theme following way. function wp_set_preview_theme( $current_theme ) { if ( ‘YOUR_IP_ADDRESS’ === $_SERVER[‘REMOTE_ADDR’] ){ // Use your preview theme instead return ‘THEME_YOU_WANT_TO_USE’; } else { // Otherwise, keep the current theme return $current_theme; } } add_filter( ‘stylesheet’, … Read more

Allowed memory size of 268435456 bytes exhausted (tried to allocate 64 bytes)?

The problem was the max memory limit. I had defined in config.php define(‘WP_MEMORY_LIMIT’, ‘512M’); But this was not working for me. But then I see , I need to define this define( ‘WP_MAX_MEMORY_LIMIT’ , ‘512M’ ); also in config.php. Now custom property type is working for me. Now I can edit this post type.