• Resolved shtv

    (@shtv)


    Hi there. Your plugin worked in hiding featured images on single post pages on my site. But it seems i have to edit each post and tick the box ‘Display featured image in post lists only, hide on singular views’ for all the posts in my site.

    I have 200 posts so it would take a very long time to do this. is there another way of achieving this? by the way thanks for the great plugin.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author cyrillbolliger

    (@cyrillbolliger)

    Hi shtv,

    Thanks for this excellent question. As this is not a very common usecase, there is no GUI support for this. However, it can be achieved easily with the WP-CLI. The featured image of a single post can be added in the WP-CLI with the following command:
    wp post meta add <POST_ID> cybocfi_hide_featured_image yes

    So to hide the featured image on all posts, the command would look like this:
    wp post list --field=ID | xargs -i% wp post meta add % cybocfi_hide_featured_image yes

    What the command does:
    * wp post list --field=ID gets the ids of all posts.
    * | passes the post ids to the next command.
    * xargs -i% executes the following command for every id and replaces the % with the current post id.
    * wp post meta add % cybocfi_hide_featured_image yes adds the meta information to the post, that the featured image should be hidden.

    Hi, thank you for this plugin. Can you please let us know the command for bulk hide using the wp database? Thank you.

    Plugin Author cyrillbolliger

    (@cyrillbolliger)

    Hi freefincal

    Thanks for your question. It depends on your excact usecase. If you want to bulk hide the featured images of all your posts, this is the SQL command to go with:

    INSERT INTO wp_postmeta (post_id, meta_key, meta_value) SELECT ID, "cybocfi_hide_featured_image", true FROM wp_posts WHERE post_type
    = "post" AND ID NOT IN (SELECT post_id FROM wp_postmeta WHERE meta_key = "cybocfi_hide_featured_image");

    (assuming you use the default wp_ table prefix).

    What the command does
    * INSERT INTO wp_postmeta (post_id, meta_key, meta_value) tells the database to add a specific meta info.
    * SELECT ID, "cybocfi_hide_featured_image", true FROM wp_posts tells it to use the posts id as post_id, the plugin specific meta key cybocfi_hide_featured_image and true in order to actually hide the image.
    * WHERE post_type = "post" specifies, which posts should be affected. In the given example, it limits the insert of the meta info to all posts (but ignores any other post type).
    * AND ID NOT IN (SELECT post_id FROM wp_postmeta WHERE meta_key = "cybocfi_hide_featured_image") makes the command idempotent, so it doesn’t matter, if you execute it multiple times. Additionally, it prevents changing any posts, that you’ve edited since you’ve installed and activated the plugin.

    Please let me know, if you have any further questions.
    Cyrill

    This worked like an absolute charm! Thank you so much. Do add a donate button. Will be happy to contribute

    • This reply was modified 4 years, 4 months ago by freefincal.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Bulk editing posts with your plugin’ is closed to new replies.