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
  • Are you using the correct table? Note you can also add a shortcode filter. – birgire Commented Mar 4, 2019 at 8:05
  • it is the correct table. how would I set a filter – user161982 Commented Mar 4, 2019 at 20:33
  • Have you looked into the shortcode_atts_gallery filter? – birgire Commented Apr 15, 2019 at 16:56
Add a comment  | 

1 Answer 1

Reset to default 0

As 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