Wordpress - Attachments block slugs - wordpress

Summary: Some uploaded attachments automatically get slugs I later want to use for posts. It is impossible to change them without database access and very annoying.
Hi everyone,
I am using wordpress and lately uploaded some images.
Subsequently I was trying to create a post with a certain slug but wordpress automatically added a "-2" to it, indicating that there was already a page using the slug.
I entered the slug into my browser and it redirected me to an image I had uploaded. Weird.
I entered phpMyAdmin and searched the database for posts with the slug.
( SELECT * FROM wp_posts w where post_name like 'my-desired-slug'; )
In the database I found an entry of an object with post_type = "attachment". It has the desired slug assigned to it ("post_name"="my-desired-slug")
It is weird that wordpress assigned the slug to an attachment. This function is very unpractical. Now I had to edit the slug in the database since wordpress does not offer a UI section to edit attachment slugs.

In the admin you can go to Media, then select a image. In the detail page on the bottom right you can click "Edit more details". In the following screen below the title you can change the permalink!

Related

Copying/Cloning Elementor content to a new post programatically so it can be translated

I am developing a plugin for Polylang that takes the content of selected posts and saves it to an XLIFF-file that can be sent to a translation agency. When the translated XLIFF is returned, I create new translated posts and link them with Polylang functions. Polylang works in such a way, that each translation is a cloned post that is linked in their database.
Everything works nicely with Classic Editor, Gutenberg and any page builder that uses shortcodes to build the post->post_content.
However, Elementor does not seem to work with shortcodes, but instead uses it's own database tables to save the content.
I can get the rendered Elementor content from a post, but that is just html and while I can save it to a post content, it can longer be edited with Elementor.
I could basically try to get the content by using the IDs I get with
$elementor->documents->get_doc_for_frontend( $post_id )->get_elements_data();, save that as translatable objects in the XLIFF, but I havent figured out how to clone the Elementor post so that there are new IDs and then replace the content in those. Or something...
Is anyone aware of existing immplementations where an Elementor-page is cloned and some of the resulting pages text content replaced?
All the relavant data is stored in the wp_postmeta table with around 10 rows per post.
In the field meta_value of post_id = '$post_id' AND meta_key = '_elementor_data' you find a JSON-like content. The parts to translate are i.e. editor, text, title.
I hope this helps - please keep me informed about further updates.

Wordpress - display author name and picture for pages/posts

What plugin or configuration option is needed to display an author name and photo for pages/posts he/she creates?
I have several editors working on the website and I'd like to display the authorship.
Suggest using get_the_author_meta() - this will let you retrieve any specific field - e.g. display_name or description (this is the Biographical Info box.)
get_the_author() will give you the name only.
WordPress doesn't support photos for authors/users out of the box, check the plugin directory.

How can I change a wordpress custom post back to a standard post?

I have inherited a legacy wordpress installation which has a complex template with a couple of custom post types.
I want to migrate it to a simpler theme and convert all the custom post types back to regular posts.
I have gone into the wp_posts table and changed the values in the post_type column from "product" or "service" or whatever back to "post" and the posts in question now load into the template, but they don't show up in the list of posts in the admin page. If I load the editor on another post, and change the ID in the url bar to one of my would-be normal posts, they will load up and I can edit them, but I just can't make them show up in the posts list.
Is there somewhere else I need to change things to make Wordpress see them as standard posts?

WordPress category link

I am trying to create an online store from scratch, with categories and product pages.
Since is my first WordPress store I'm stuck on this trivial problem which stopped me on my way.
The permalinks are set to Month and name just to know the settings.
I created several categories where I want to insert the future products.
The problem arise when I try to access a certain category link - www.mysite.com/category/books/ - it displays the error page.
If I access www.mysite.com/category/ it shows me the content of the category page created in the admin panel.
All I want to do is to display all books when the visitor clicks on www.mysite.com/category/books/ and so on.
It is simple. Go to wp-admin/options-permalink.php and make your own settings: /%category%/%postname%/
And add a prefix on the field below: category or whatever you want
Read here for more options
Actually I solved it in another way, by modifying the category.php page.
There I inserted this code :
$uri = $_SERVER['REQUEST_URI'];
$elms = explode('/', $uri) ;
$catName = $elms[4] ;
and it does the thing I need.

Inserting a link to another post in Wordpress

I'm putting together a site based on a Wordpress template, and was wondering if there's a way to link one post to another without entering the full URL. I'd like to be able to use something that doesn't change if the parent directory or subdomain changes. Any ideas?
Posts
To link to a Post, find the ID of the target post on the Posts administration panel, and insert it in place of the '123' in this link:
Post Title
Categories
To link to a Category, find the ID of the target Category on the Categories administration panel, and insert it in place of the '7' in this link:
Category Title
Pages
To link to a Page, find the ID of the target Page on the Pages administration panel, and insert it in place of the '42' in this link:
Page title
(From Wordpress)
Linking Posts, Pages, and Categories
Something like: Post Title should work even if you use permalinks.
use below code to get particular post url and Title only by post id.
replace $postid with your post id that you want to display.
$postid = 1;
echo ''.get_the_title($postid).'';

Resources