Support

Account

Home Forums ACF PRO Adding a custom field to a custom post type list page in admin

Solved

Adding a custom field to a custom post type list page in admin

  • Hi,

    I have created a custom post type called Playlists using the “Custom Post Type UI” plugin.
    Using ACF Pro I was able to add custom fields to the “Playlist” post page.
    Now I want to add a custom field to the “Playlists” page in wp-admin (one where you see all the posts). URL: /wp-admin/edit.php?post_type=playlist (screenshot attached)

    The idea is to select top 5 playlist posts. I would prefer that it can be done on the “list” page of wp-admin.

    Thanks

  • Hey Jags,

    What you’re talking about is the customisation of the Posts list table. This is done via functions.php using the two following hooks:

    I actually saved a gist which provides a similar music based example.

    I hope this helps!

    Dan

  • Hey Dan,

    Your reply went to my spam! I used an alternate approach in meantime.
    But I was not trying to add columns to the table but rather add custom fields on the post list page itself.
    Is that doable with ACF?

    Thanks,
    Jags

  • That is what @morgyface was showing you. YOu need to add custom columns to the list page and then add the content for each post.

  • I think he is talking about displaying columns for custom field in a playlist whereas I need editable fields for the listing page.
    Maybe I have this pictured incorrectly (technically) in my head but see attached screenshot.

    Thanks

  • I’ve got a feeling @jags would like to assign custom fields to the Posts list page itself as its own entity and I’m pretty sure that’s not possible. However, I think what you could do is customise the in-built filter to achieve the same result.

    https://wordpress.stackexchange.com/questions/16637/how-to-filter-post-listing-in-wp-dashboard-posts-listing-using-a-custom-field/16641

  • Hey @jags, okay I think I know what you want to achieve, but I think you’ll need to apply the playlist position field to the playlist post itself. You could then customise the post lists screen to show the playlist position column and data for each post.

    I’m guessing you’re aiming for an end result of being able to edit the playlist position via the post lists page itself. This could be done, by exploring the customisation of “quick edit”, but it doesn’t look like an easy task.

    The other thing you could do, and this might be more straightforward, is use taxonomies. You could create a “position” taxonomy and then have terms for the position, you could have first, second, third and standard. It looks like Custom Post Type UI has a feature that allows you to add taxonomies to quick edit.

  • Thanks for detailed reply Dan.
    This is the 1st time I am using ACF and after googling for 1hr I kind of felt what I was trying to achieve does not exactly falls into standard behaviour.
    But ACF homepage said “Fields can be added all over WP” so I thought maybe I am missing something obvious. Glad to know that I wasn’t 🙂

    I will stick to custom field on the page for this.

  • There is an ACF quick edit plugin floating around somewhere, or at least there was at one time.

  • OK, I know this is an older post, and I came about it while searching for a better solution to the one I have for a similar problem.
    As far as I’m concerned I also have a custom post type too and I want to ad user-editable information to the archive page (I guess that is what the OP meant by ‘list-page’.)

    It is quite simple to to one of two things:

    A) one makes a template archive-{cpt-slug}.php that does usual loop over the custom-post-type-posts and add information from acf-field from elsewhere (e.g.an options-page) and displays it before or after the standard loop.

    B) One builds a custom page template that has a custom-query loop restricted to the desired cpt and sets up a regular page that displays the acf content that is connected to said page-template.

    Both options are working rather well but both have their drawbacks. Option A keeps the usual WordPress mechanics intact but it is hard for editors to know where to edit the content as with archive-pages there is no WP-standard way of editing them and the wp-admin-bar lacks a link to edit the contents. Option B offers an edit Page link in the admin-bar but might break the wp-core mechanics, and looking for a page as the source of an archive is for expedierend wp-users counter-intuitive.

    It is indeed a WP-problem, that editor-editable content for archives including cpt-archives is not part of the system.

    Even categories have at least their description field and one could at (least in theory) add additional field at that intended location. (I’m rather certain I have done so in the past.) But with custom post types there is (to my best knowledge) no such logical place for editing such information.

    On can try to remedy the problems of option A or B with certain tricks like for option A
    Adding a custom link to the settings page in the admin-bar when the cpt-archive is displayed at the frontend and/or moving said settings page int a submenu oft the cpt-menu in the backend. Or with option B setting redirects to the page in htacces or using the cpt-slug as the page slug. But it doesn’t really solve the problem there is no native place in WorpPress for editable content on an archive page, or am I wrong?

  • You are not wrong. WP provides nowhere to edit content for the main taxonomy archive page = archive-{cpt-slug}.php

    The only way to accomplish this is to add your own admin page, like an ACF options page.

    Nor is there a place in the DB set aside to store this information, it must be stored in the options table.

    Or as an alternative as a “Page” with a custom page template.

    archive-{cpt-slug}.php could be used to load this custom page template, or the page template could be used to load archive-{cpt-slug}.php via get_template_part().

  • True. I would love to do the variant where archive-{cpt-slug}.php loads the custom page template, but I don’t see how to get the editable content into the archive page without hardcoding the/a page-id into it, wich seem like bad practice to me. Or am I missing something?

  • Well, actually.

    WE has a setting “page_for_posts”. in the “archive.php” template used to show the blog archive you can get this value and then get fields from that page ID.

    You could add more settings “page_for-{$CPT}” using to the settings page https://developer.wordpress.org/reference/functions/add_settings_field/

Viewing 13 posts - 1 through 13 (of 13 total)

The topic ‘Adding a custom field to a custom post type list page in admin’ is closed to new replies.