How can i get the last post from wp multisite?

The orderby-parameter should be post_date instead of date. your code would look something like this: $blogs = get_last_updated(‘ ‘, 0, 1); foreach ($blogs AS $blog) { switch_to_blog($blog[“blog_id”]); $args = array( ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’, ‘numberposts’ => 1, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘suppress_filters’ => true ); $lastposts = get_posts( $args ); foreach($lastposts … Read more

Why use %d in php when in function

$wpdb->prepare() supports a small subset of the sprintf() arguments. The %d is a placeholder for an integer (not a decimal, that would be %f). Use %d when you want to send a real integer to the database, use %s for strings. An example: $post_id = ‘2’; $prepared = $wpdb->prepare( “SELECT * FROM $wpdb->posts WHERE post_id … Read more

Remove css styles from specific page

You can use conditional tags to target the specific page you need to remove the styles on. You can use is_page() to target a page page (as opposed to another post type) and pass a page ID, slug, title, or no argument to target any page. function wpse_217881_remove_scripts() { // Check for the page you … Read more

Checking for user role in a custom plugin

Why it doesn’t work for a Plugin: It doesn’t work for plugin because by the time WordPress executes $current_user = wp_get_current_user(); in a plugin, the function wp_get_current_user() isn’t defined yet. WordPress loads that plugin file before it defines those user related functions. However, it works for theme because WordPress loads theme after it defines and … Read more

How can I set custom order use this function

You will need to add term meta to your categories. In this metafield you will store the string or number that you want to use as a base for your custom order (tutorial). Let’s say you have generated a meta field called my_cat_meta which holds integers that say in which order you want them to … Read more