Wordpress showing 404 page template for unpublished posts - wordpress

When I open a URL that point to a post which is not published yet, wordpress shows a 404 page. But I want to show a meaningfull message to user that "your post is not published by admin, please contact admin to get it published"
How can I do this?
Edit: Is their any way i can get wordpress to run my single.php template instead of 404 template in my case?

I am not sure, just a hint add script kinda like this to single.php:
if($post['post_status'] == "publish"){
//do something
}else {
// it's not published (i.e. draft or other) so do nothing
}
just do print_r($post) and it will show the full array with keys and values.
good luck !

make url of the unpublished posts something like this.
http://yoursite.com/?p=587&preview=true
And put charlie if else condition in single.php but remember user have to be logged in to see the preview of the post

You can Show unpublished posts, instead of 404 page template by using the_posts filter.
For more information visit this page.

Related

is there anyway to send notification of new Post is published in wordpress to another page of same website?

I'm creating a wordpress plugin in which i want that if new post is published the notification gone on another page of same wordpress website.
Thanks
There is a few ways todo this. But I would do it this way.
When you create a post, you add a post_meta to that post that tells that this page is new.
Then you have an cronjob or something that is running an wp_query that are searching for all posts that have that post_meta. And when it finds the new post/posts it either clear that post_meta or set it to false.
And then on the page that you wanted to display it somehow, use that cronwork to update that page or something like it.
Hard to describe more when I don't know what that other page should do with the information about the new post

Creating user profile pages in wordpress

What I'm trying to achieve is to make each user on the website(the wp-users) have their own unique front-end profile pages like so site.com/user/userX. (EDIT: To clarify, it is not a settings page that only the user himself can see, it's a open profile page for logged users or anonymous/visitors to access and see its profile)
I thought about using the url GET (site.com/user?name=userX) in a post but wordpress doesn't seems to understand "?..=.." and says page doesn't exist. This solution does not look like a good practice in wordpress so I'm trying to look from another perspective.
Even tho there are a couple of plugins there that would do that for me and more, I'm stuck with doing manually since I'm building a multi-language website (using Polylang), so plugins will only work in the main language.
Briefly, Polylang keeps track of the language through url, ex.: site.com/langX/pageX, and the plugins I've tried are stuck to one page only.
I'm inclined to say what I'm looking for is a way in the functions.php to make Wordpress understand that a page .../user/ will expect a name right after .../user/userX like that I can use the same function for multiple languages : ...langX/user/userX, ...langY/user/userX ...
I'd be glad if someone could put me in the right direction of what should I be looking for.
for security you should create a new route in wordpress :
function custom_rewrite_basic() {
add_rewrite_rule('^user/([0-9]+)/?', 'index.php?user_profile=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_basic');
function custom_rewrite_tag() {
add_rewrite_tag('%user_profile%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);
Now, you can access the same page as :
http://example.com/user/95
this code in your theme :
get_header();
global $wp_query;
if($wp_query->query_vars['user_profile']) {
//do stuff
}
From my understanding, what you can try is to create a page from dashboard, named user or something. Once users are logged in, you can get user info in session or you can use the query vars as you mentioned above. You can create custom page templates in Wordpress and assign that template to the page. In this page template write the frontend html-s with required logic. Routing in WordPress is normally handled by WordPress itself. So creating a page will make that route say yoursite.com/user available for you. Please read on page templates from the below link from WordPress documentation.
https://developer.wordpress.org/themes/template-files-section/page-template-files/
UPDATED ANSWER
As per the comments
Create a custom post type which holds the data(users)
When a user registers, create the entry for users post type, link user id to that post type entry with a post meta. You can set a unique url for the user by setting the slug as you need.
Provide users the ability to edit only their own data. You can check the post meta which connects user id with that particular custom post type item.
If a user gets removed, delete their custom post type entry as well, so that nothing remains in the DB related to the user.

Wordpress Facebook Instant Articles not seeing our articles / content

Before the community dismisses this - this is not a repeat of other issues with the Facebook submission process. Were a non-profit looking for help getting this running.
We have many articles on our website but we are not able to get them to appear in https://childmind.org/feed/instant-articles
I am not able to see where you instruct the FB Instant Articles WordPress plugin which content you want to publish e.g. our articles aren't in /blog but rather in /article e.g. https://childmind.org/article/adhd-behavior-problems/
Everything else is configured seemingly properly. Does anyone have an idea?
After we get articles in the feed, we can submit for review.
NOTE: We have edited and saved articles to "trigger" them being added but has not worked.
Articles sound like a custom post type which you need to manually tell the plugin by using a filter for your CPT.
add_filter( 'instant_articles_post_types', 'add_post_types', 10,1 );
function add_post_types($post_type_array){
array_push($post_type_array,'post'); // Standard post "blog"
array_push($post_type_array,'articles'); // The name of your custom post.
return $post_type_array;
}
This should then get pull the articles for the feed as long as everything else has been set up correctly. Taken from a post on the WP Plugin forum.
Note: Also, Facebook have their own validation process once you get this working before you will start to see them on Facebook.

I don't know why Wordpress worked follow that way

I have a problem with a Wordpress permalink.
These are my steps to show the problem:
1) in admin > pages: I create new page call "GoodMorning" and I have slug "goodmorning", on frontend, I run ://my_domain/goodmorning will show the content of this page
2) Now, I run ://my_domain/find-me/goodmorning it will auto redirect to ://my_domain/goodmorning
/find-me/ : this is any name and this text does not exist on wordpress slug, category, page, post, ....
Please let me know why. I want it to show a 404 page when I run ://my_domain/find-me/goodmorning.
Thanks All.
Adding this (to functions.php) should stop that redirect.
remove_action('template_redirect', 'redirect_canonical');
If you look at the documentation for redirect_canonical here:
Will also attempt to find the correct link when a user enters a URL that does not exist based on exact WordPress query. Will instead try to parse the URL or query in an attempt to figure the correct page to go to.
I assume that's what you're trying to prevent based on your question.
If you need the other functionality of redirect_canonical you can just cancel the redirect by returning false to this filter, like so:
add_filter('redirect_canonical', '__return_false');
You need to flush your permalinks configuration afterwards:
In the main menu find "Settings > Permalinks".
Scroll down if needed and click "Save Changes".
Rewrite rules and permalinks are flushed.

wordpress custom post type

So I've just made a custom post type for my wordpress theme named "Products". When I create a new post in it and view it, the link is something like this:
"http://localhost/wordpress/product/a-product-title"
This page views as expected but when I try to go to the supposed parent page:
"http://localhost/wordpress/product/"
I get a 404 error page. Is there a special template I need to make to view this page?
Thanks
I found what to do. I just created a new page called "Products" and set it as the posts page. Then I put this in front of the loop
$wp_query = new WP_Query("post_type=product");
and it worked
I had the same issue - I think it's down to the fact that right now, WP 3.0 simply does not behave as you would expect with custom post type 'archives'.
Check out Smarter Custom Posts to easily build-in this behaviour.
The name Products is also used by Woocommerce so be aware that if you install this too, the custom post type will stop working.

Resources