Repository navigation
Check for ACF and a specific ACF field and display if possible. - #122
Conversation
|
@tlongren Thanks so much for the Pull Request! I love this idea and would be glad to accept the PR if you can modify it to work without the Advanced Custom Fields plugin (i.e., if someone creates the You should be able to simply change this: if ( is_plugin_active( 'advanced-custom-fields/acf.php' ) && get_field('primary_category') )to this: if ( get_field('primary_category') )Also, to prevent any possible naming collisions, I would like to call the field |
|
Excellent points @raamdev, and I totally agree. I had forgotten get_field() would also grab the standard WP custom fields, too. So, I'll get this fixed up this afternoon and attach the commits here. Thank you, sir! |
|
Here you go, @raamdev. Updated custom field name and only checking for that field Missing word in a comment, :/ Seems to work well, it's running at longren.io right now, but only for the most recent 10 or so posts maybe. |
Check post custom field for primary category on single posts This allows a site owner to show only one category on the post when the post has been assigned to multiple categories.
|
Merged. Thank you! :) |
|
@tlongren I noticed while testing the dev branch of Independent Publisher that I was getting PHP notices about get_field('independent_publisher_primary_category')with get_post_meta( get_the_ID(), 'independent_publisher_primary_category', true )I assume that since the ACF plugin just works with WordPress custom fields, this code change shouldn't affect the goal of your Pull Request here, but if that's not true, please do let me know. :) |
I've been using this setup to allow me to choose which category is shown when viewing a single post. ACF could be setup in various ways, but as long as the field is named
primary_category, and it's not a file field, this should work.If ACF and the
primary_categoryACF field don't exist (ie: the plugin isn't enabled or hasn't been configured), we fall back to the original category display.Thought others may like this. I'll have a blog post about my exact setup later on today.