WPBook Custom Post Types?
-
Does it work?
Seems like it does NOT work. Since we switched to Custom Post Types yesterday, no posts are being published to Facebook.Any way to solve this issue?
This is the plugin we’re using for custom post types:
https://labs.dagensskiva.com/plugins/more-types/It’s called “More Types”.
-
It doesn’t, right now. It specifically doesn’t post custom post types at the moment as the WP Lifestream plugin was creating hundreds of custom posts for people.
In publish_to_facebook.php at lines 34-36 you’ll see this:
if(get_post_type($my_post->ID) != 'post') { // only do this for posts return; }
You can just eliminate that whole if statement if you want all custom posts to be published to FB, or decide which you want to include.
John, thank you for this! You guys are awesome.
Man, I can’t get it to work.
This snippet is correct, right? See below.
} if(get_post_type($my_post->ID) != 'post, nyheter') { // only do this for posts return; }
The two post types being post and nyheter.
I’m not getting any errors or so, it’s just not publishing.
Try this
if((get_post_type($my_post->ID) != 'post) || (get_post_type($my_post->ID) != 'nyheter')){ // only do this for posts return; }
OR
if(get_post_type($my_post->ID) != 'post','nyheter')){ // only do this for posts return; }
There may be a better (more logical) way to write this but you were saying that if post type did not = “post, nyheter” when what you wanted to say was “Post” OR “nyheter” I’m not sure what the syntax of
get_post_type
is if it’s an array or not.After some research it looks like my first snippet was correct. So I would try that first. ??
It works!
Very grateful.How do I add on more post types if I create any in the future?
I’m having some issues with this…
I used a theme for my site which involves using what I believe to be custom post types. I found this thread and thought for sure it was the answer to all my problems. I’ve been fiddling with it for hours now with no luck. I used the first snippet from BandonRandon as follows:
if((get_post_type($my_post->ID) != 'post') || (get_post_type($my_post->ID) != 'video')){ // only do this for posts return; }
I’m pretty new to .php, so I will paste in the code from the functions.php from the theme I am using. I’m assuming I’m missing something here?
add_action('init', 'gallery_register'); function gallery_register() { $labels = array( 'name' => _x('Image gallery', 'post type general name'), 'singular_name' => _x('Gallery Item', 'post type singular name'), 'add_new' => _x('Add New', 'gallery item'), 'add_new_item' => __('Add New gallery Item'), 'edit_item' => __('Edit gallery Item'), 'new_item' => __('New gallery Item'), 'view_item' => __('View Gallery Item'), 'search_items' => __('Search gallery'), 'not_found' => __('Nothing found'), 'not_found_in_trash' => __('Nothing found in Trash'), 'parent_item_colon' => '' ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'query_var' => true, 'menu_icon' => get_stylesheet_directory_uri() . '/images/mbewizz.png', 'rewrite' => true, 'capability_type' => 'post', 'hierarchical' => false, 'menu_position' => null, 'supports' => array('title','editor','thumbnail') ); register_post_type( 'gallery' , $args ); } add_action('init', 'video_register'); function video_register() { $labels = array( 'name' => _x('Video Gallery', 'post type general name'), 'singular_name' => _x('video Item', 'post type singular name'), 'add_new' => _x('Add New', 'video item'), 'add_new_item' => __('Add New video Item'), 'edit_item' => __('Edit video Item'), 'new_item' => __('New video Item'), 'view_item' => __('View video Item'), 'search_items' => __('Search video'), 'not_found' => __('Nothing found'), 'not_found_in_trash' => __('Nothing found in Trash'), 'parent_item_colon' => '' ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'query_var' => true, 'menu_icon' => get_stylesheet_directory_uri() . '/images/videowizz.png', 'rewrite' => true, 'capability_type' => 'post', 'hierarchical' => false, 'menu_position' => null, 'supports' => array('title','editor','thumbnail','comments') ); register_post_type( 'video' , $args ); } register_taxonomy("Categories", array("video"), array("hierarchical" => true, "label" => "Video Categories", "singular_label" => "Category", "rewrite" => true)); add_action( 'admin_menu', 'my_page_excerpt_meta_box' );
Any help with this would be greatly appreciated, for I am stumped…
My guess is that if that code needs to be in the functions.php for your theme, you’ll need to add a functions.php to the wpbook/theme/ directory.
Basically WPBook substitutes the wpbook/theme/ for your ‘regular’ theme when it is called from inside Facebook – so WordPress at that point would not have access to the theme’s functions from your usual theme.
You’ve also got a logic error in the first snippet:
if((get_post_type($my_post->ID) != 'post') || (get_post_type($my_post->ID) != 'video')){ // only do this for posts return; }
This says, basically, if the type of the current item is not ‘post’ OR the type of the current item is not ‘video’, skip this item.
But that will always be true. You need an AND not an OR:
If the type of the current item is not ‘post’ and is not ‘video’ skip this item.
That looks like this:
if((get_post_type($my_post->ID) != 'post') && (get_post_type($my_post->ID) != 'video')){ // only do this for posts return; }
You may need another && for the ‘gallery’ type as well, based on the code you provided.
I appreciate your quick response and help!
I’ve made the changes you’ve suggested (I think).
I duplicated the functions.php file located in wp-content/themes/mytheme/ and placed it at wpbook/theme/functions.php
I changed the OR to an AND as you suggested as well.
I don’t notice any change on my Facebook apps page? It’s still not showing any of my video posts.
I also added the ‘gallery’ type.
if((get_post_type($my_post->ID) != 'post') && (get_post_type($my_post->ID) != 'video') && (get_post_type($my_post->ID) != 'gallery'))){ // only do this for posts return; }
I’ve been up all night trying to figure this one out. I was hoping it was something stupid I was overlooking…
The change we made to the OR/AND logic only applies when you are publishing a post, and want an excerpt on a Facebook wall.
The application canvas page itself uses a standard WordPress ‘loop’ in wpbook/theme/index.php, lines 280-281:
if (have_posts()) : while (have_posts()) :
There are ways to get custom post types into that loop, using a custom query – see “Displaying Custom Post Type Posts” in this blog post: https://www.wpbeginner.com/wp-tutorials/how-to-use-custom-post-types/
You’d have to add a different post query listing the post types you want to include – something like:
query_posts(array('post_type' => array('post', 'video','gallery')));
This would need to come before the if(have_posts) above.
NOTE: This isn’t currently supported by WPBook and you will most likely need to remake these changes each time you upgrade. As WP 3.1 nears it will apparently allow other post types in the standard loop, though I haven’t really investigated it enough.
Wow, you’ve opened up a whole new world for me. I was unable to get it to work right away, but now I have the tools to figure it out.
Thanks for your help!
I’ll repost when I put it all together…
- The topic ‘WPBook Custom Post Types?’ is closed to new replies.