How to get right link (permalink) to a exact wordpress post? - php

I have a website that is a custom PHP site hosted at http://mysite.com. Then I have a Wordpress instance running on sub-domain at http://blog.mysite.com, where some post can be at URL http://blog.mysite.com/this-is-my-test-post-entry
In landing page of mysite.com I connect to Wordpress DB and fetch out last 5 entries from wp_posts table and show them on my home page. The problem is I don't know how to get the right links to those posts? Wordpress generates permalinks() but I don't know how to get them?
I thought Wordpress takes post title string and replaces spaces with "-" and uses that string for post URL. But doesn't work for all posts...
Any suggestions?

This may not be exactly what you are looking for, but it will work...
When you fetch your last 5 posts, get the id (make sure you're filtering on your post_type field to avoid grabbing things like revisions, attachments, etc).
You can simply build your URL like http://blog.mysite.com/?p=ID (where ID is the ID from the database). WordPress will automatically redirect the user to the proper page with the custom permalink that you defined in your settings.
Let me know if you need a hand with the PHP.

Related

How Change Meta Title on Individual URL in Post Pagination Wordpress

I have site on wordpress, but i'am use automatic pagination every post.
On pagination, then I made an article so that all posts are visible with the url, example https://bisnis.cilacap.info/pertamina-ru-iv-cilacap-transfer-pertalite?singlepage=all. This url work and no error in cpanel.
But the Meta Title is missing, and I want to make it into existence. Can any friend help me and implement it in function.php

Can i show all posts from one wordpress site to other wordpress site with separate domain as prefix to all posts?

I have wordpress site with domain lets say abc.com and other wordpress site on separate domain with separate database lets say xyz.com.
And all i want to get and show all existing posts from first domain to second domain.
For example: If a post is on first domain lets say abc.com/post-1 then i want to show this post on second domain xyz.com/post-1.
Edit 1: All posts meta data, slug, content and featured image stored on first domain's database.
Maybe you could use the REST API tool: https://developer.wordpress.org/rest-api/using-the-rest-api/ to get the post list (json type) and then treat it on your website.

Multiple Permalink for Single Post in Wordpress

I have a worpdress website that is set with a permalink structure to:
mywebsite.com/%author%/%postname%/
Now, I have a post that is written by multiple authors - what we wanted to achieve is that we should suppose to be able to access the post by going to any of the author in the url such as:
mywebsite.com/author1/mypost
mywebsite.com/author2/mypost
This actually works, however for some reason when I go to:
mywebsite.com/author2/mypost
this redirects to this:
mywebsite.com/author1/mypost
I think this is due to the base permalink wordpress enforces?
How do I make it so that when I go to the link of a certain author, it will retain the author in the permalink?
eg.
Going to mywebsite.com/author2/mypost should direct to mywebsite.com/author2/mypost

Custom Permalink with Page Name Wordpress

I have looked all over the place and can't figure out how to get this to work.
I want my urls for blog posts to look like this: "www.website.com/my-page/category-name/blog-post-title"
The issue I am having is that I have a page called "my-page".
So I have a page "www.website.com/my-page/" which is just a standard wordpress page, but I want the url for the blog post to look like it is under that page.
Here is what I have for the permalink so far:
/my-page/%category%/%postname%/
But this doesn't work and gets a 404 error when opening a blog post.
At this point I don't believe it can be fixed through the wordpress gui, so if anyone has any recommendations, it would be appreciated.
Thanks!
Edit: I wanted to add that the permalink works fine if I remove "/my-page" or if I simply modify it so it does not match the page.
First of all you should not use the category in front of your permalinks as it leads to bad performance (and some posts may have multiple categories): http://ottopress.com/2010/category-in-permalinks-considered-harmful/
The second thing is - it should work. I tried with a fresh installation on WordPress and I get the correct results.
Did you flush rewrite rules / save the new permalink structure?
Did you publish a post?
Is your server correctly configured to use permalinks?
Third possibility - if your permalink structure does not work for some reason you can define a custom permalink structure:
https://codex.wordpress.org/Rewrite_API

Is it possible to make a customised Wordpress, seo friendly, url?

I need to change the customized URl of wordpress, where I pass the id in querystring to get data from my custom table. Now i want to see the title instead of that id.
Ex. My site link id http://xyz.com/?page_id=1&pid=12
Now if i try the wordpress permalink it will convert the wp page only like http://xyz.com/test?pid=12
What can i do to make the URl like http://xyz.com/test/title. Where title is stored in database for pid=12.
Yes this is possible and actually pretty easy. Go to /wp-admin/options-permalink.php and look for the custom option that you want. You must have access to the server to update the .htaccess file. Here is more info.
if you want the name of your page to appear as in:
http://www.xyz.com/about/
instead of something like:
http://www.xyz.com/?page_id=398
login to your back end of wordpress
under the settings menu(on left side) click permalinks
click custom structure and in the text field type in:
/%postname%/

Categories