• Resolved Goldfinch44

    (@goldfinch44)


    Hi, I’m trying to add the php to the fpw_template_filters.php file, and it’s not working. Am I adding the code to the wrong file? Or in the wrong place? I tried to follow your directions, I think I’m missing something.

    (Goal is I have two custom post types, “books” and “authors”, and would like to feature a book and author each month

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author mrwweb

    (@mrwweb)

    Hi @goldfinch44.

    First off, you never want to directly edit a plugin, theme, or core WordPress file. Any changes you make will be lost when you update the plugin/theme/WordPress.

    This is what filters and actions are for. You can safely add support for additional post types in this plugin using the fpw_post_types filter (referenced in the FAQ). You can see examples of how to use that in this gist.

    The code you write should go in your theme’s functions.php file or a custom plugin for your site.

    Thread Starter Goldfinch44

    (@goldfinch44)

    OK yes I’m totally not a php guy, sorry – so I added the code (for adding a post type, not removing one) on your gist page to my theme’s functions.php file, changed your example “book” to mine, “books”, and it’s still not working. Is there a plugin you recommend I can add the php to and maybe that’ll work?

    Plugin Author mrwweb

    (@mrwweb)

    It sounds like that should be working, so I’m not quite sure what to tell you. I’d double-check that “book” is the actual slug of your custom post type. For example if you go to the “All Books” page of your admin, it’ll be at a URL like this:

    https://example.com/wp-admin/edit.php?post_type=xyz_books

    In that case, “xyz_books” is the value the filter will need. I wouldn’t recommend a PHP execution plugin. If you want to try something else, try an mu-plugin.

    Thread Starter Goldfinch44

    (@goldfinch44)

    okay, got it to work, thanks for bearing with me. NOW… I want to have TWO custom post types added, but if I paste that snippet twice I get an error. Do I just append another post type to that filter? If so, where exactly?

    Plugin Author mrwweb

    (@mrwweb)

    For posterity, can you post your solution to help other people?

    You can’t declare the same function name twice. Instead, you just need to add a second post type to the $post_types array:

    
    <?php
    add_filter( 'fpw_post_types', 'fpw_add_post_type_to_feature' );
    function fpw_add_post_type_to_feature( $post_types ) {
    	$post_types[] = 'book';
    	$post_types[] = 'another_post_type'; /* ADD THIS LINE */
    	return $post_types;
    }
    ?>
    
    Thread Starter Goldfinch44

    (@goldfinch44)

    I redid everything you told me to do above, and this time it worked. I don’t know if it was a cache thing keeping it from working, or what. For example, after I just added “authors,” it took quite a while for it to work, after several cache purges. (Can you tell I’m not super technical?)

    THANKS!!

    Plugin Author mrwweb

    (@mrwweb)

    Glad I could help ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Custom Post types not working’ is closed to new replies.