Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example on how to meta query ACF repeater fields
<?php
add_shortcode( 'user_company_link', 'yanco_user_company_link' );
function yanco_user_company_link() {
if( ! is_user_logged_in() ) {
return;
}
$html = '';
$current_user = wp_get_current_user();
$current_user_id = $current_user->ID;
// Check if the user is attached to any companies
$query_args = array(
'post_type' => 'virksomhed',
'post_status' => 'publish',
'suppress_filters' => false,
'meta_query' => array(
'relation' => 'OR',
array (
'key' => 'acf_virksomhed_admins_$_user',
'value' => $current_user_id,
),
array(
'key' => 'acf_virksomhed_users_$_user',
'value' => $current_user_id,
)
),
);
$query = new WP_Query( $query_args );
if( count( $query->posts ) ) {
}
}
add_filter('posts_where', 'yanco_posts_where');
function yanco_posts_where( $where ) {
$where = str_replace( "meta_key = 'acf_virksomhed_admins_$", "meta_key LIKE 'acf_virksomhed_admins_%", $where );
$where = str_replace( "meta_key = 'acf_virksomhed_users_$", "meta_key LIKE 'acf_virksomhed_users_%", $where );
return $where;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.