Skip to content

Instantly share code, notes, and snippets.

View mariokerkhof's full-sized avatar

Mario Kerkhof mariokerkhof

  • Rotterdam
View GitHub Profile
// Filter to fix the Post Author Dropdown
add_filter('wp_dropdown_users', 'theme_post_author_override');
function theme_post_author_override($output)
{
global $post, $user_ID;
// return if this isn't the theme author override dropdown
if (!preg_match('/post_author_override/', $output)) return $output;
// return if we've already replaced the list (end recursion)
// Pas alleen '=bidirectional_relationship' aan naar de juiste veldnaam. werkt ook tussen verschillende CPT's. veld kan apart aangemaakt worden in verschillende groepen, als het maar dezelfde naam heeft.
function bidirectional_acf_update_value( $value, $post_id, $field ) {
// vars
$field_name = $field['name'];
$global_name = 'is_updating_' . $field_name;
// bail early if this filter was triggered from the update_field() function called within the loop below
if( $column_name == 'teams' ) {
if( have_rows('Stand') ){
while ( have_rows('Stand') ) : the_row();
// http://www.advancedcustomfields.com/resources/post-object/
// https://codex.wordpress.org/Class_Reference/WP_Post#Accessing_the_WP_Post_Object
$post_objects = get_sub_field('team');
echo $post_objects->ID; // Display the post's ID
echo apply_filters( 'the_content', $post_objects->post_title ); // Do this instead
@mariokerkhof
mariokerkhof / mkr_helper_functions.php
Created January 30, 2016 12:57
MKR Helper Functions
<?php
//
// Template helper functions
//
function mkr_is_first_post( $query = false ) {
if ( ! $query ) {
global $wp_query;
$query = $wp_query;
@mariokerkhof
mariokerkhof / functions.php
Last active February 1, 2016 09:12
Remove User Role
// Delete role
remove_role( 'coordinator' );
@mariokerkhof
mariokerkhof / functions.php
Last active February 1, 2016 09:12
Add User Role
// Add role (voer dit eenmalig uit)
// Voeg coordinator toe
$result = add_role(
'coordinator',
__( 'Coördinator' ),
array(
'read' => true,
'edit_posts' => true,
'delete_posts' => false,
// Sorteer Taxonomy field op volgorde naam in dashboard
function mkr_acf_taxonomy_field_dashboard_order( $args, $field, $post_id ) {
$args['orderby'] = 'name';
$args['order'] = 'DESC';
// return
return $args;
}
add_filter('acf/fields/taxonomy/query/name=gebied', 'mkr_acf_taxonomy_field_dashboard_order', 10, 3);
@mariokerkhof
mariokerkhof / gist:fe3649285554a3fde8c1
Created January 30, 2016 10:28
ACF Disable Editing Standard Fields for user role
// Disable een standaard tekst veld(werkt niet op input en select fields)
function mkr_acf_disable_text_fields( $field ) {
$user_role = 'coordinator';
if( current_user_can( $user_role )) {
$field['disabled'] = 1;
} else {
$field['disabled'] = 0;
}
@mariokerkhof
mariokerkhof / gist:678da45549b544630b85
Created January 30, 2016 08:58
ACF Disable Editing Input Fields For User Role
function mkr_acf_disable_fields_competitie() {
// Add the role that !!can not!! edit here
$user_role = 'coordinator';
if( current_user_can( $user_role ) ) { ?>
<script type="text/javascript">
(function($) {
@mariokerkhof
mariokerkhof / gist:6ab4684de2da731929a9
Last active February 1, 2016 09:11
ACF Repeater Sort by Field in Dashboard
function mkr_acf_repeater_sort_dashboard( $value, $post_id, $field ) {
$order = array();
if( empty($value) ) {
return $value;
}
// Order
foreach( $value as $i => $row ) {