instant articles for custom post type
-
How do I enable Instant Article for custom post type?
-
Instant Articles plugin has a filter that you can configure to specify the post types that you want to be processed as Instant Articles to facebook.
The filter call can be found in “class-instant-articles-publisher.php”
$post_types = apply_filters( 'instant_articles_post_types', array( 'post' ) );
so what you need to do, in your “functions.php” :
add_filter( 'instant_articles_post_types', 'add_post_types', 10,1 ); function add_post_types($post_type_array){ array_push($post_type_array,'post_type_name_1'); array_push($post_type_array,'post_type_name_2'); array_push($post_type_array,'post_type_name_3'); return $post_type_array; }
replace ‘post_type_name_X’ with your custom post type & add to filter as many types as needed
Credit to Paulo in
https://www.ads-software.com/support/topic/v30-allow-filtering-of-post-types-used-in-the-feed-how?replies=4#post-8636476Can I remove the default ‘post’ post type? We’d only want to enable instant articles in a custom post type.
you can add the code I’ve provided earlier in your theme functions.php file, the only thing you need to change is replace ‘post_type_name_1’ with your custom post type name
sorry @gatta2, didn’t read your question correctly.
yes, you should be able to remove the default ‘post’ post type by resetting the array before pushing new post types to it, you can add extra line
$post_type_array = array();
which makes the complete code look like:
add_filter( 'instant_articles_post_types', 'add_post_types', 10,1 ); function add_post_types($post_type_array){ $post_type_array = array(); array_push($post_type_array,'post_type_name_1'); array_push($post_type_array,'post_type_name_2'); array_push($post_type_array,'post_type_name_3'); return $post_type_array; }
give it a try & wright here how it goes
Hello @huthayfa,
I tried your recommendation for adding additional post types but it’s not working. I’m guessing it’s because I’m trying to add it to a ‘page’ post type. Is there a limitation where it will not add it to a ‘page’ post type? If not, how can I achieve adding it to my pages as well as posts. Here is the code that I have added/tested:add_filter( 'instant_articles_post_types', 'add_post_types', 10,1 ); function add_post_types($post_type_array){ $post_type_array = array(); array_push($post_type_array,'post'); array_push($post_type_array,'page'); return $post_type_array; }
Any help with this is greatly appreciated. Thank you!
- This reply was modified 8 years, 2 months ago by jasonblackdog.
As far as I know, adding a page to be pushed as an instant article is not possible, because pages doesn’t live in the normal time based listing as of a post, which means a page cannot be converted to a ‘feed’ & that is essential to generate an instant article.
Hello @huthayfa,
Adding the filter is working great for most of my custom post types, but I’m seeing a custom field with key “instant_articles_submission_id” now for them, but no instant articles meta box. Is that expected and how could I make them behave like normal posts where the instant articles meta box is shown and custom field with key “instant_articles_submission_id” is not?
Thank you,
CourtHi @courtb,
This has been solved in the new version, make sure to update your plugin to 3.2. However if you prefer not to update the plugin you can get the meta box by modifying the
register_meta_box
function inplugins/fb-instant-articles/meta-box/class-instant-articles-meta-box.php
, the new function should be:public static function register_meta_box() { add_meta_box( 'instant_article_meta_box', 'Facebook Instant Articles', array( 'Instant_Articles_Meta_Box', 'render_meta_box_loader' ), /** This filter is defined in facebook-instant-articles.php. */ apply_filters( 'instant_articles_post_types', array( 'post' ) ), 'normal', 'default' ); }
Regards,
HuthayfaThanks @huthayfa,
The new version works great. I had tried updating with an earlier release and it broke, but I see a lot of bug fixes are in 3.2.
@huthayfa I can’t thank you enough! That worked! I was looking high / low for an answer and see they are building it into the plug in for version 3.4 with an UI but I couldn’t wait till it was released.
Thanks!
Hello,
Some of my custom post types store info in post meta boxes. I see in the readme that it says there are hooks I can use to provide this content, but I don’t see them documented anywhere. Can you tell me what the hook would be for adding such an item? Am I just missing something?
From the readme file:
“It’s important to note that if you use meta fields to add extra text, images or videos to your Posts, Facebook will expect you to add these to your Instant Articles output too. This plugin includes hooks to help you do that.”Thank you,
Courtopen your theme folder,opern function.php then add these filters it may work
add_filter( 'instant_articles_post_types', 'add_post_types', 10,1 ); function add_post_types($post_type_array){ array_push($post_type_array,'your-custom-post-type'); return $post_type_array; }
replace
your-custom-post-type
with your posttypeHelly Mukhthar,
You misunderstand me slightly. I have no problem getting the custom post type to show data stored in the post content. Where the problem resides is trying to get content stored in meta fields. The documentation states there are hooks to allow for this, but those hooks are not mentioned. I did a lot of digging for “do_action” in the plugin and found the “instant_articles_after_transform_post” hook, which I then searched for and found this answer:
https://www.ads-software.com/support/topic/include-custom-fields-in-feed/
After that, I only needed to use the paragraph element instead of the video one.
this solution seems out of date with current latest version.. anyone?
how to filter post tags?
- The topic ‘instant articles for custom post type’ is closed to new replies.