0

I have the Newspaper theme, installed custom post plugin and ACF plugin pro with ACF plugin to copypaste code somewhere.

Setting up both in backend was easy but the last part I do not understand.
Where (which file, which line) must I paste the PHP code to show up in custom post type?

Looking through all files I did not find any new ones named as my custom post type, same results with notepad++ searching inside all files also.
On ACF forum answer cant be found as devs are not giving support to the usage of ACF on custom post types.

closed as off-topic by Michael, Jacob Peattie, cjbj, bueltge, Jack Johansson Dec 16 '17 at 11:48

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

3

You have to get familiar with template hierarchy to understand in which template WordPress will display your custom post type. If you have sample custom post type named event with title Lorem ipsum, WordPress will watch for this files in that order in your theme to display such a custom post type:

  • single-$post_type-$slug.php for our case it will be single-event-lorem-ipsum.php
  • single-$post_type.php for our case it will be single-event.php
  • single.php
  • singluar.php
  • index.php

If WordPress will not find first of the file from list it will be looking for second and so on.

Most of the themes has single.php file and probably your custom post type will be displayed by this template. Good practice would be to create separate template file for custom post type, probably you want to display it display differently than others post, named single-event.php. For start I would copy single.php content, paste it to single-event.php file and add there your ACF code.

  • Name of the custom post type is event. i have tried with single-event.php and with event.php. I am not sure where to paste code ? Original single.php has some php code inside and finishes with get_footer. I added code 3 lines before and tried at beggining but no luck. – Azz Kawa Dec 6 '17 at 22:57
  • event.php is wrong you should try with single-event.php or single.php. Where to paste the code? If ACF fields have custom values for each event you should place code inside loop. Somewhere between while ( $query->have_posts() ): and endwhile;. If editing php files is overwhelming for you you can try display ACF fields with shortcodes placed in your content e.g. [acf field="name"] where name is your field name. I do not have enough information to help you more, what theme you are using? – kierzniak Dec 7 '17 at 8:37
  • Thx motivast. I have tried with default single.php and single-event.php. Using Newspaper theme from CodeCanyon. Did not find lines you mention where i should add php code. I searched whole theme folder with notepad++ for those lines but no luck. Maybe its important, custom post type is made with plugin Custom Post Type UI 1.5.6. and PostTypeSlug is named event. I will also try [acf field="name"] on single.php. – Azz Kawa Dec 7 '17 at 14:56
  • Tried [acf field="name"], no luck. Its proly becouse i am not sure where to add this in single.php. – Azz Kawa Dec 7 '17 at 14:59
  • I have this Newspaper theme themeforest.net/item/newspaper/5489609. I don't know if you have it to. If yes I have opened loop-single.php file and paste <?php the_field('test'); ?> code after <?php echo $td_mod_single->get_content();?>. My value from this field showed after post content and banner. – kierzniak Dec 7 '17 at 15:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.