I just found url_to_postid and I'm using it in my function. It works on posts that is in draft or posts that are published. It is not working for posts that are in trash. Trashed posts are soft deleted which means you can still restore it but url_to_postid is not working.
$postId = url_to_postid($pageUrl);
I need it to be able to also get the post id of trashed posts. Is there any way to do this?
Related
I have an issue where all posts that are older than two days are missing. They are not in the trash in Wordpress, and if you go to the URL, it will come back with a 404.
I've tried disabling all plugins and repairing the tables in PHPMyAdmin as well as using the /wp-admin/maint/repair.php
I also have activated wp_debug and looked at the log; however there is nothing relating to this issue.
Now when I check the database in PHPMyAdmin - I can see all the posts there.
I've compared the posts that are currently published to the ones that are missing and the only difference I can see if that the post_status is set to "inherited" opposed to saying "published".
If I update the post_status of a missing post to "published" then edit the post in Wp-admin with the ID, eg, post.php?post=[missing post id]&action=edit it will show the missing post for about 2 seconds (including all the content) then redirect to an edit media page with every field blank.
I assume some plugin made this change, figuring out which one is the hard part.
Let me know if you need any more details from my end.
If a post is not viewable in WP dashboard but searchable in SQL table this could mean a revision has not been published (or the published revision has disappeared from the table). To turn on a revision see you must change post_type to 'post' and post_status to 'publish'
make a post viewable in phpmyadmin
I have encountered this problem many times. This problem only happen when I programmatically create/edit posts. They could be customs post or even Wordpress' default post. The symptoms could be:
The posts are not visible in admin dashboard. Post count of that custom post type still increase but no post is displayed in the list.
Created posts are not query-able, even when post_status is set to 'any'. Curiously when I set post_status to published it works.
This is a self-answered question. I encountered this problem several times before and always forget its cause. And searches hint to possibilities that many others are stuck without solution too.
TL;DR;: It's publish, not published.
The cause of this problem is because I when programmatically create new posts, I set its post_status to published. Common reason for the confusion is when you approve a post programmatically, switching post status from pending to published because it seem logical.
The reason those posts are showing in neither queries nor admin dashboard is because WP_Query's post_status => 'any' doesn't actually query for 'any' post status as we expect, but any registered post status. Since wordpress had no prior knowledge of the post status published, they're simply ignored by the queries.
Now here's to hope I don't forget what I wrote today again next year.
I'm am creating a simple administration system for one of my sites, and now I am creating a blog inspired by WordPress' posts system.
In my blog you can save it as either a draft or a published version.
And now I want to create a way, so when you delete a blog, it will change to "trashed" in the database. And when you restore it, it will be restored as the same type again, just like WordPress.
But how do WordPress restore it's trashed posts, to the original post_status? I have looked at the WordPress database, but I couldn't figure out, how it does it, cause the original post_status is replaced with "trash" when it is trashed and is not stored any other place in the table.
So how does it "remember" it's original post_status? Hope you understand what I'm asking :D
Sorry for not being a code-related question, but I couldn't find any answer any other places.
Thanks
To be short:
The previous post-status of a WordPress post, is stored in the wp_postmeta table.
In that table, the time for when the post were trashed, also are stored.
If you then restore the post, the rows of containing data for that specific post, are removed.
That should answer your question.
This is basic stuff to be frank. You should look at the wp_posts table and see the difference between a trashed and a published post ( and possibly, others too). Wordpress does this by changing the post_status column for that particular row of data. This way it knows the current status of the post concerned.
It might not be related to the answer but for those who are looking for answer to this question, should consider looking at the data source, i.e. the database of any system you are trying to learn... Be it Wordpress or Moodle.
All the posts, pages, and cpts are stored in {table_prefix}_postsin the database.
The posts, pages, or cpts which are trashed have the post_status as trash in some cases the permalink is also changed to __trashed
e.g; http://example.com/sample-page__trashed
To restore the post page, change the post_status back to published and remove __trashed from the permalink if it exists.
I recently fixed the issue on the site which was using the 'Frontend User Pro' plugin and the login page and reset password page was trashed. The site was not working and I fixed it using the above method.
I'm using get_delete_post_link() on the front-end of my website which allows blog post authors to delete their posts.
My question is, when this link is used to delete a post, does the post meta get deleted also?
Hoping somebody can help explain.
Thanks in advance.
If you are using it without any argument, then post will be moved into trash. Trashed post do keep post meta.
But if you supply the third argument to true, then post will be permanently delete including meta informations.
// first argument post_id
// second one deprecated
// third one is force_delete, which deletes post permanently including post meta.
get_delete_post_link(null, '', true);
I've search everywhere but haven't found what I'mlooking for even though I'm convinced there must be a solution floating around since it's obviously such a common request:
I want to display a list of authors with a short excerpt of their latest post.
I have a list of Authors with their images (using the 'Author Avatars List') but what I'm missing is the display of an excerpt of their latest posts next/under their image.
Any thoughts?
Thanks in advance!
JD
Edit 26 Sept
I realize from the First two answers my question was a bit to fuzzy - the emphasis should have been on the 'authors avatars list' wp plugin (http://wordpress.org/extend/plugins/author-avatars/).
In the meantime I have created the following solution:
http://wordpress.org/support/topic/plugin-author-avatars-list-get-display-excerpt-of-authors-last-post?replies=2#post-1710752
Thanks for you input!
JD
From get_posts() , you can get all the posts , since each post has a post_author property, you can get all the posts written by each author with a foreach loop, from this you get the latest post per author , and from the latest post , get the post_excerpt content.
Assuming you're using Wordpress...
I'd do a hybrid direct SQL and loop approach.
Query for user_ids from the user table who also have a post_author present in the posts table. Loop over those IDs to get their user object and then their latest post. The only thing you lose here is fine grained control over the ordering of users.
Here is the solution:
http://wordpress.org/support/topic/plugin-author-avatars-list-get-display-excerpt-of-authors-last-post?replies=2#post-1710752