Get author ID with attachment ID

Back in the day I wrote a function to check for that (you can put it in functions.php and call it from your page): public function check_if_user_is_author($user_id, $post_id) { global $wpdb; $res = $wpdb->get_results($wpdb->prepare(“SELECT * FROM ” . $wpdb->posts .” WHERE ID = %d AND post_author = %d LIMIT 1″, $post_id, $user_id)); if(isset($res) && count($res) … Read more

Get comment content by comment ID

The Codex makes it seem like you can query for a specific comment by ID, as does the GenerateWP query generator, but I couldn’t get it to work with either of those examples. Even looking through the WP_Comment_Query:query() code makes it clear that you should be able to pass the ID in the parameters. That … Read more

Does the menu item ID ever change?

WordPress menus are their own Post Type ( nav_menu_item ). Every time you add a new item to a menu it create a new “post” in the nav_menu_item post type and assigns it a new ID just as deleting and recreating a page removes / adds new ids. This means the only way the Navigation … Read more

Exclude main blog from get_blogs_of_user

If you drop this line in your code, you will see all the properties of $user_blogs. echo ‘<pre>’.print_r($user_blogs,true).'</pre>’; One of them is userblog_id, so you just have to check against it before echoing the blogname. <?php $user_blogs = get_blogs_of_user( $user_id ); if (!$user_blogs) { echo ‘no blogs’; } else { echo ‘<div><ul>’; foreach ( $user_blogs … Read more

Creating a Front-end based User Search

As you haven’t offered the details on what you’re after, I’ll try to grab them all very briefly. Use the API – public WP_User_Query API functions Basically get_user_by() should be enough for you. Let’s say you fire of your form and the input field name was user_id. So you’d just retrieve the value from the … Read more

Get the correct post id for all post and page in header.php

get_queried_object_id() will return the ID of the current single post or page being viewed, as well as the static front page. For any type of archive page (except date, custom post type and home archives), the following will be returned: Category ID of the category archive being viewed Tag ID of the current tag archive … Read more

Categories id Tags

Undefined variable post_id in custom quick edit coloumn

Sorry, I’ve had to change my answer after checking the WordPress Codex on adding custom editable data to the quick edit. So you’ll have to remove the references to $post_id too (from the add_action arguments and from within your function). It looks like the quick_edit_custom_box only takes 2 arguments: $column_name and $post_type. Then for getting … Read more