I’m using a document type URL to set the main document, but in the item view, it shows the URL. I know that I can enable the option Render content in iframe, but I have thousands of items with this document. So, I would like to know if there is a snippet or code to enable the ‘Render content in iframe’ by default.
If you’re reusing an image as the main document you should enable both “Render content in iframe” and “Is link to external image” options.
Sadly we do not have bulk editing features for document options yet. In particular we consider it may be rare that one would put tons of items with the same document, but I believe you might have some good reason for that.
Meanwhile, what you can do with a bit of effort is use the WP CLI for that. Because those settings are stored as Post Meta named document_options in the Item object. They are something like this:
The script would be something like this (not tested, please run first with a single item):
COLLECTION_ID=123
POST_TYPE="tnc_col_${COLLECTION_ID}_item"
META='{"forced_iframe":true,"forced_iframe_width":600,"forced_iframe_height":450,"is_image":false}'
for ID in $(wp post list --post_type="$POST_TYPE" --format=ids); do
wp post meta update $ID document_options "$META"
done
Depending of which is your collection ID (123) and of course if you don’t want to apply to all items in the collection you may modify this to something like an array of Item IDs
The reason I’m trying to do this is because I’m working on a kind of harvester that gets items from other repositories, so I get the URL in document type for each item (approx. 50k items), and the URL contains an image that is different for each item. That’s the context.
So, I tried with the script in a testing collection and the result message is:
Success: Updated custom field ‘document_options’.
Success: Updated custom field ‘document_options’.
But in the item view, it doesn’t show the forced iframe and in the ‘Edit item’ option doesn’t apply the option yet. Do you have any idea?
Success: Value passed for custom field 'document_options' is unchanged.
{"forced_iframe":true,"forced_iframe_width":600,"forced_iframe_height":450,"is_image":true}
Success: Value passed for custom field 'document_options' is unchanged.
{"forced_iframe":true,"forced_iframe_width":600,"forced_iframe_height":450,"is_image":true}
But still it shows the link URL and not the forced iframe.
Since the document_options is an array we cannot pass it like that, which is a string encoded version of that array. To give an array value to the wp cli command you’ll need wp eval, which runs php function calls. So the updated version:
COLLECTION_ID=123
POST_TYPE="tnc_col_${COLLECTION_ID}_item"
PHP_ARRAY="
[
'forced_iframe' => true,
'forced_iframe_width' => 600,
'forced_iframe_height' => 450,
'is_image' => false,
]
"
for ID in $(wp post list --post_type="$POST_TYPE" --format=ids); do
wp eval "update_post_meta($ID, 'your_meta_key', $PHP_ARRAY);"
done