Open Jeremy-Bolella opened 5 years ago
You can't add an ACF field to a Oxygen Template, because where would it show up?? You would add your fields to a Custom Post Type and then use the field date in your single post template see this https://oxygenbuilder.com/documentation/templating/advanced-custom-fields/ Or you could add the custom field to an options menu if it is a global field you want to use inside a template.
The ACF "block" feature is only for ACF registered Blocks that you have created, you can't just add fields to any gutenberg block. this is what you are getting at I believe -- https://support.advancedcustomfields.com/forums/topic/acf-for-gutenberg-block-settings/
I can understand Gutenberg blocks being the trickier scenario to get the correct hooks in place especially since like you said ACF registered blocks are just that ACF registered. Which would require a large amount of ACF specific code to implement with the current Oxy block library.
With the template scenario this is default theme behavior. I'm aware that there's no "theme" when it comes to oxygen. It's also not much of a question of where it would show up as far as matching what a traditional theme does when you ACF target a specific page template. I'd see this as a general WordPress functionality not something that would require any ACF integration.
Defining templates without actual files also seems to be possible in WordPress although the solution looks to be not so elegant: https://wordpress.stackexchange.com/questions/142952/define-custom-page-template-without-its-own-php-file
Well a page template and an oxygen template are not the same thing at all. Whats your actual use case that you aren't able to accomplish? you have me wondering now?
and ya ACF usage inside other blocks would be nice hey! we can dream ;)
One of the most recent examples was a template that would change the general color of the page. For all intents it was just a regular page, not something that would warrant the overhead of a CPT. Since there was no way to target this slightly different template I ended up having to do some funky javascript magic targeting a logo on the page that would trigger the page color change. There are probably better ways to do it but because I didn't have a way to do it with ACF I ended up with a brittle solution that'll require more dev time if new pages with different logos are added (unlikely but it could happen).
Ahh I totally get you know, you don't want to show the field on all Pages only when a given oxygen template is selected. I think the easiest request to ask of oxygen would be to simply have a class applied to the backend of WP that matches the template selected, then we could simply show the fields for all "pages" in ACF and just hide those fields with css and display them when the editor has a given class. That would be a fairly quick implementation, I'll play with just using a js solution to grab the selected drop down and applying a class based off that to the #wpwrap div when I have some time. Should be fairly quick to do that.
Another Though, would be to add a taxonomy to "pages" not done often but totally legit https://thewphosting.com/add-categories-tags-pages-wordpress/ so that then you could add the ACF field to pages with that Taxonomy.... and you could assign the Oxygen template you want to use based on taxonomy, so that way instead of choosing your oxygen template and have the ACF fields appear you would just choose your page category and the correct template and ACF fields would show up. Would that work for your use?
If I'm hearing correctly: You want to be able to select by 'oxygen template' in the ACF field group location settings?
If so, here's a helper class that'll give you the options you need:
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
class Digitalis_OXY_ACF {
public function __construct() {
$this->add_filters();
}
private function add_filters() {
add_filter('acf/location/rule_types', [$this, 'location_rules']);
add_filter('acf/location/rule_values/oxy-template', [$this, 'location_values_oxy_template']);
add_filter('acf/location/rule_match/oxy-template', [$this, 'location_match_oxy_template'], 10, 4);
}
public function location_rules ( $choices ) {
$choices['Oxygen']['oxy-template'] = 'Oxygen Template';
return $choices;
}
function location_values_oxy_template ( $choices ) {
global $wpdb;
$templates = $wpdb->get_results(
"SELECT id, post_title
FROM $wpdb->posts as post
WHERE post_type = 'ct_template'
AND post.post_status IN ('publish')"
);
if( $templates ) {
foreach($templates as $template) {
$template_type = get_post_meta($template->id, 'ct_template_type', true);
if (!($template_type == "reusable_part")) {
$choices[ $template->id ] = $template->post_title;
}
}
}
return $choices;
}
public function location_match_oxy_template ( $match, $rule, $options, $field_group = false ) {
$current_template = get_post_meta( $options['post_id'], 'ct_other_template', true );
$selected_template = (int) $rule['value'];
if($rule['operator'] == "=="){
$match = ( $current_template == $selected_template );
} elseif($rule['operator'] == "!=") {
$match = ( $current_template != $selected_template );
}
return $match;
}
}
new Digitalis_OXY_ACF();
Thank you so much for spending the time to make that! It's very close to working the fields now populate when creating a custom field but it seems like we're missing a hook to have the fields show up on the actual page unfortunately.
Nevermind I take that back. For anyone who might see this in the future, you must choose the template for the specific page. Say for my homepage it defaulted to the front template you'll have to manually click front page template and the ACF Fields will populate!
Thank you again perrelet! This is going to be a huge benefit to my workflow. I'll actually be using this functionality today in my current project.
My pleasure, happy to help Jeremy.
Yep - I guess if you wanted to do it without explicitly selecting the oxy template for the post, you'd need to add some additional logic to detect the 'default template'...
Oxygen isn't designed to work this way. Moving to feature requests.
i need to if i change RENDER PAGE USING TEMPLATE change acf filed another template another acf filed
help anyone
Honestly @hasnattanvir I think your best bet would be to create an ACF selectlist that has all your template names listed with conditionals, and just make it so you select the case study single then under ACF fields also choose Case Study Single with conditional fields to show the fields. ya kinda annoying but really simple and only takes 2 seconds to select the matching template.
Thanks, nickfmc i have another problem in oxygen i use dynamic text in single page but , have a default p tag and it can't remove I have checked the settings and options within Oxygen Builder, but I couldn't find any specific option to disable or remove these default p tag.
Describe the bug Blocks and Templates built in Oxygen are not populated in the ACF plugin. There seems to be a missing hook to populate the template/block information over to ACF.
Have you tried all the steps at https://oxygenbuilder.com/documentation/troubleshooting/troubleshooting-guide/? Yes
Are you able to replicate the issue on a Sandbox install at https://oxygenbuilder.com/try? The bug needs the ACF plugin installed to work. But it is reproducible below.
To Reproduce Steps to reproduce the behavior:
For Template Bug:
For Gutenberg blocks:
To note the blocks can be found under specific posts Type in ACF, this targets the Global block config in oxygen which is also not right.
Expected behavior In the ACF drop downs for template/blocks the Oxygen generated templates/blocks show up so field groups can be targeted at the respective type.
What actually happens In Both Cases of block/template the data is just not there for ACF to be able to target. This limits the flexibility of building with Oxygen blocks without jumping into custom coded blocks.
Desktop (please complete the following information): MacOS, Chrome, Oxygen Version: 3.1.1 (This is an issue on all versions)
Additional context If I could I could figure out this issue myself I would make a plugin to export the template/block data to ACF. I think this is such a crucial feature to really complete oxygen.
Things like blocks with resource links (That can vary by block) are only possible with ACF without jankily doing it in rich text.
If there is anything I can do to help solve this bug/feature a point in the right direction would be enough for me to develop the solution.