Inserting tags outside of the loop problem (Difficult)
-
Hi there guys I’m trying to set post tags outside of the loop and the approach works partially: tags are created and linked to the post correctly, that is they appear when editing the post in BUT when listing tags within the dashboard, the counters are set to 0 as if unused by any post.
Basically I’m using MySQL code to access data with
// Gain acces to the DB $link = mysqli_connect("localhost", "root", "") or die("Could not connect: " . mysqli_error()); mysqli_select_db($link, "mydbname"); // read data $querystr = "SELECT * FROM tj_posts"; $result = mysqli_query($link, $querystr); $row = mysqli_fetch_array($result, MYSQL_ASSOC)) $curID = $row["ID"]; $newtitle = "Hello"; $newcontent = "Some content here"; // Modifiy post using SQL $query="UPDATE tj_posts SET post_title='$newtitle', post_content='$newcontent' WHERE ID='$curID'"; mysqli_query($link, $query) or die("Update error: " . mysqli_error()); // Update works correctly till here // now the tags - Point to the post using WP API $post = get_post($Id, ARRAY_A); // set some tags wp_set_post_tags($ID, "red, alcholic, bottled"); mysqli_free_result($result); echo "Done!";
- The topic ‘Inserting tags outside of the loop problem (Difficult)’ is closed to new replies.