Filter images from media library by guid meta field

I am using the ajax_query_attachments_args filter attempting to remove certain images from the wordpress media library. They are all in a separate folder within the uploads directory called "speakers-bureau" which is why I am trying the guid meta query. Here is my code add_filter('ajax_query_attachments_args', 'remove_speakers_bureau_images'); function remove_speakers_bureau_images($query) { $query['meta_query'] = [ [ 'key' => 'guid', 'value' => 'speakers-bureau', 'compare' => 'NOT LIKE', ] ]; return $query; } The idea being to only show images that are not in that folder, …
Category: Web

Accidently changed the GUID

I accidently executed: UPDATE yemnc_posts SET guid = REPLACE(post_content, 'domainA', 'domainB'); instead of UPDATE yemnc_posts SET guid = REPLACE(guid, 'domainA', 'domainB'); How can I undo this? Is this even possible? What could be a solution? Hope you can help me :)
Category: Web

How to change all the guid in posts table?

Recently I have transferred my WordPress from development server to live server. I noticed that I have to change all the "guid" with live domain url. Is there any mysql query or simple function available to change it easily.
Category: Web

how to Update guid = "text"+post_name?

in phpmyadmin, i use this SQL command to update all posts that have guid like '%/?p=%' = "https:/bkfast.vn/"+post_name update lgs_posts set guid='https://bkfast.vn'&'post_name' where guid like '%/?p=%' But it's error: Truncated Pls help me update all posts that have guid like '%/?p=%' = "https:/bkfast.vn/"+post_name Old: https://bkfast.vn/p=2258 -> New: https://bkfast.vn/ky-thuat-trong-rau-thuy-canh-tinh Info: post_name varchar(200); guid varchar(255)
Category: Web

Moving WP install from local to live, what about wp_posts GUID?

Done this before and i am still wondering what to do with the wp_posts => guid content, which has reference to http://localhost But at wordpress.org documentation it clearly states: Never, ever, change the contents of the GUID column, under any circumstances. But as i understand it is just to unique identify your posts globally. But as more people would have http://localhost in their guid. So can i safely replace http://localhost with http://example.com ? regards
Category: Web

What is the difference between these GUID's in wordpress feed?

My RSS feed currently contains generated post GUIDs URLs that use the post slug: <guid isPermaLink="false">https://sitename.com/postname/</guid> However I want to use the ?p=postID format instead: <guid isPermaLink="false">https://sitename.com/?p=3566</guid> How can I change this? Thanks in advance!
Category: Web

Change old URLs after the domain change

I have setup wordpress on my server, and after some time I've changed the domain name of the installation. However, all of the old urls within the site point to the old domain. How can I change old urls to match the new domain without breaking the database? Here's what I did: I went to settings -> general I've changed the site url and wordpress address (url). The directory in which the wordpress installation is residing stayed the same. How …
Category: Web

wp_posts - guid update

Hello and please excuse if this has been answered before but we really need to make sure. We have developed a website under a domain of ours and then moved it to the live site of the client. We have run a few sql queries in the db in order to update to the new url but when we search our domain name in the database, we get: 600+ matches inside table wp_posts (mostly revisions, but there are attachments and …
Category: Web

I have a site where attachments in the wp_posts table have guid values of guid, how did this happen?

I realise comparing this particular website with all the other WP sites I've built that all the others have the image url in the guid column of the wp_posts table, yet this problem site just has "guid" as the value of the guid column for ALL it's image/attachment entries. The site still seems to work fine... if I go to the "Media" area of the admin it lists all the uploaded images correctly. I assume the code is looking at …
Category: Web

Set Attachment Image File URL as GUID

I have a form that uploads images and i want to update the GUID to be the attachment file url after WP generates the metadata. I tried to use wp_update_post, but seems that is not updating the guid. $attachments = get_posts($post_data); if ($attachments) { // attach images to gallery foreach ($attachments as $attachment) { wp_update_post(array( 'ID' => $attachment->ID, 'post_status' => 'inherit', 'post_parent' => $gallery_post_id, 'guid' = wp_get_attachment_url($attachment->ID); ) ); } } Any suggestions ?
Category: Web

Is it safe to add a new field to meta_value field?

I'm trying to offload Wordpress images from my web server. I've successfully moved everything over to Amazon AWS and have a syncing mechanism in place that uploads new images to AWS. Now I would like to store a flag somewhere that indicates whether the image has been synced so my custom theme can pick the correct path. I was thinking adding that flag to the wp_postmeta table, as part of the meta_value serialized object. Is that a safe technique? What …
Category: Web

How to introduce Permalinks into pop-u-lar widget?

I am using the pop-u-lar widget on my blog, which is linking to the selected posts by their "guid"s. However, the site itself is using human-readable links instead and I want the widget to do the same. The widget uses a "for each" loop with the variable $post, so I thought get_the_permalink($post) would do the job, but it seems the refer to the site url instead. Basically it is about this line of code: <a href="<?php echo $post->guid ?>"><?php echo …
Category: Web

Add guid filter to attachment in media library grid mode

I'm trying to show in media modal box, attachments from a specific folder in my website and, correct me if I'm wrong, the best way to proceed is a like filter on wp_posts field GUID. Something like and ({$wpdb->posts}.guid LIKE '%/uploads_media_news/%')). Problem is I don't really know where to apply this filter: is it better to act on backbone.js? On a .php file, perhaps ajax-actions.php? I don't really know what to do anymore, I've been working on this change for …
Category: Web

Custom permalink for each post

im importing data from Drupal to WP. I have more than 10 000 posts. Each post have ID, category and slug. For example: Category> important ID> 11111 Slug> hello-world I need to keep permalinks same like they are on drupal because of SEO: www.wordpress.com/important/11111-hello-world The problem is that, i cant insert post with ID 11111 until is database index set to this number. If i do import, this post will actually much smaller, never the same like on drupal. I …
Category: Web

Creating posts from API data, how to identify posts already imported?

As the title says, I'm using an API to fetch some data which is used to create CPT posts, and need to identify items returned from the API which have already been inserted as posts. The API returns unique IDs for each item, which naturally leads me toward just making use of the GUID column, but I've read, in no uncertain terms, to never make use of the GUID. If touching the GUID is taboo, is there an accepted standard …
Category: Web

Moving WordPress Directory (same domain) - GUID issue?

I have a WordPress installation on a directory within my domain. So, it is like this: www.example.com/blog/ WordPress is placed in /blog/ I'd like to move the WordPress installation Blog Posts back to the root level. When I exported the XML file I noticed that each blog post had this GUID reference: <guid isPermaLink="false">http://example.com/blog/?p=1275</guid> >> notice the /blog/ in the URL << So, my question is - if I import the XML file into a fresh WordPress install at the …
Category: Web

How to identifty post from its URL in 404 page?

Why GUID is such unstable? Some of the post's GUID are pretty permalinked, but most of them are default. I's using Pippin's function to get the post_id from its GUID, but it's not working if my site is using pretty permalink, and the GUID is default. But it's working on those posts only, where the GUID is pretty permalinked. I tried using url_to_postid() too - same result. I'm actually failing doing such redirection where posts that are expired (post_status expired) …
Category: Web

GUID to related post not in current language

I'm having problems with related posts and the link to them. I'm using the plugin Posts 2 Posts to create connections between posts. I also have three languages in wordpress website (french, english, dutch). I can get the related news articles by creating this query: $connected = new WP_Query( array( 'connected_type' => 'project_to_post', 'connected_items' => $post, 'posts_per_page' => 3 ) ); I get one news item (that's correct) and the title, body, ... are all in the correct language (dutch …
Category: Web

Are there some caveats for using guids for FB comments

I'm using Facebook comments box and just realized that when we use <div class="fb-comments" data-href="<?php the_permalink(); ?>" data-width="100%" data-numposts="5"></div> and then realize our title is wrong, changing the title (and slug in the process) we lose all social counts because they are tied to the url. So I was wondering why I'm not using <div class="fb-comments" data-href="<?php the_guid(); ?>" data-width="100%" data-numposts="5"></div> instead. The url as domain.com/?p=10000 doesn't change even if the slug/url or what ever would change. Are there some …
Category: Web

Is it risky if I update all url in the database due to my site url changed?

Let's say I have a wordpress site on a subdomain. Initially, I created the site with "www." >>> www.mysite.mainsite.com Now, I'd like to change site url to only mysite.mainsite.com without www anymore. I can change it via Settting > General but I checked the database and I found that all of my images in media library (guid field of the posts table) are still having www.mysite.mainsite.com with www which I don't want it anymore. I also found this thread related …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.