How to retrieve the content (with a specific ID) via ajax by clicking a link tag

I would put the action in the post data $.ajax({ url: “/wp-admin/admin-ajax.php”, type:”POST”, data: { action: “my_custom_data”, post_link: post_ID }, success: function (response) { console.log(response); $(‘#post-data’).append(response); } }); return false; ….. Then use $_POST[‘post_link’] in your PHP function my_custom_data(){ $post_link = $_POST[‘post_link’]; echo get_the_content($post_link); die(); }

Getting the wrong page ID

As mentioned in the comments, you are trying to get the ID in the taxonomy archive (template-taxonomy.php) which is not a post object and has no record in the database. It just tries to show some posts and you may get the first post ID when you use get_te_ID() function in that archive page. Using … Read more

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)