Created
October 26, 2015 17:13
Polylang: Fix missing value on ACF relational fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Polylang: Fix missing value on ACF relational fields | |
Plugin Description: ACF relational Field value for translated posts types where not displayed when Admin langauge differs from post language. | |
Author: Jörn Lund | |
Author URI: http://github.org/mcguffin | |
Version: 0.0.1 | |
*/ | |
/** | |
* Polylang addon | |
*/ | |
function polylang_acf_relational_field_fix_value_display( $query ) { | |
global $polylang; | |
if ( is_admin() && ($post = get_post() ) && ( $post_lang = pll_get_post_language($post->ID) ) && pll_current_language() !== $post_lang ) { | |
// set | |
$query->set('lang',$post_lang); | |
} | |
} | |
function polylang_acf_relational_field_fix_on() { | |
add_action( 'parse_query' , 'polylang_acf_relational_field_fix_value_display' , 9 ); | |
} | |
function polylang_acf_relational_field_fix_off() { | |
remove_action( 'parse_query' , 'polylang_acf_relational_field_fix_value_display' , 9 ); | |
} | |
add_action("acf/render_field/type=post_object", 'polylang_acf_relational_field_fix_on', 9, 1); | |
add_action("acf/render_field/type=post_object", 'polylang_acf_relational_field_fix_off', 11, 1); | |
add_action("acf/render_field/type=page_link", 'polylang_acf_relational_field_fix_on', 9, 1); | |
add_action("acf/render_field/type=page_link", 'polylang_acf_relational_field_fix_off', 11, 1); | |
add_action("acf/render_field/type=relationship", 'polylang_acf_relational_field_fix_on', 9, 1); | |
add_action("acf/render_field/type=relationship", 'polylang_acf_relational_field_fix_off', 11, 1); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doesn't work...