admin管理员组文章数量:1432566
PHP/SQL noob here. Based on this question I attempted to change some entries in phpmyadmin for my wordpress blog: I want to all galleries to link to file instead to file attachment (add link="file"
to [gallery]
shortcode). For that I used 'gallery type="rectangular"'
as a search pattern.
However, my attempt (below) is not working. For some posts, I also tried to manually edit the table entries in the database, with no effect either. Yet, when I change something in my wordpress interface, the effect becomes visible immediately both on my homepage and in the database. What I am missing here? Is this even a good idea, and if not, are there alternatives?
UPDATE
mydb.wor9400_posts
SET
post_content =
REPLACE
(
post_content,
'gallery type="rectangular"',
'gallery type="rectangular" link="file"'
)
WHERE
post_content LIKE '%gallery type="rectangular"%'
PHP/SQL noob here. Based on this question I attempted to change some entries in phpmyadmin for my wordpress blog: I want to all galleries to link to file instead to file attachment (add link="file"
to [gallery]
shortcode). For that I used 'gallery type="rectangular"'
as a search pattern.
However, my attempt (below) is not working. For some posts, I also tried to manually edit the table entries in the database, with no effect either. Yet, when I change something in my wordpress interface, the effect becomes visible immediately both on my homepage and in the database. What I am missing here? Is this even a good idea, and if not, are there alternatives?
UPDATE
mydb.wor9400_posts
SET
post_content =
REPLACE
(
post_content,
'gallery type="rectangular"',
'gallery type="rectangular" link="file"'
)
WHERE
post_content LIKE '%gallery type="rectangular"%'
Share
Improve this question
asked Mar 3, 2019 at 11:45
user161982user161982
3
|
1 Answer
Reset to default 0As Birgire mentioned in the comments, you can hook into the gallery output rather than performing a search/replace on the database.
From the WordPress Codex: Function Reference/shortcode atts gallery
Provides the ability to filter the array returned from shortcode_atts().
You want something like this:
add_filter( 'shortcode_atts_gallery', 'gallery_shortcode_exclude_thumbnail', 10, 3 );
function gallery_shortcode_exclude_thumbnail( $result, $defaults, $atts ) {
if ( empty( $atts['link'] ) ) {
$result['link'] = 'file';
}
return $result;
}
Note: you may want to remove or change the condition empty check, depending on your needs.
本文标签: shortcodeSQL query to bulk change short code in all posts
版权声明:本文标题:shortcode - SQL query to bulk change short code in all posts 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745585953a2664907.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
shortcode_atts_gallery
filter? – birgire Commented Apr 15, 2019 at 16:56