Query Posts -> By ACF custom field Value

Question

I’m using ACF and would like to create a query for the post_type elemzesek WHERE the given post has a custom field = get_field(‘ceg_megadasa’) with the value of $ceg (the given company)

Here’s my loop:

    <!-- ÖSSZES ELEMZÉS -->
    
                    <div id="elemzesek" class="p-3">
    
                        <?php
    $ceg = get_field('ceg_megadasa');
    $idcode = get_field('feed_id');
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $query = new WP_Query( array(
        'post_type' => 'elemzesek',
        'meta_key' => $ceg,
        'meta_value' => $idcode,
        'posts_per_page' => 10,
        'paged' => $paged,
        'post_status' => 'publish',
        'orderby' => 'date',
        'order' => 'ASC'
        
        
    ) );
?>



                    <?php if ( $query->have_posts() ) : ?>

                    <!-- begin loop -->

                    <?php while ( $query->have_posts() ) : $query->the_post(); ?>



                    <h2 class="pt-2"><a href=" <?php the_permalink(); ?>" title="Read"><?php the_title(); ?></a></h2>
                    <?php the_excerpt(); ?>
                    <?php echo get_the_date(); ?>

                    <?php endwhile; ?>
                    <!-- end loop -->


                    <div class="pagination">
                        <?php 
        echo paginate_links( array(
            'base'         => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
            'total'        => $query->max_num_pages,
            'current'      => max( 1, get_query_var( 'paged' ) ),
            'format'       => '?paged=%#%',
            'show_all'     => false,
            'type'         => 'plain',
            'end_size'     => 2,
            'mid_size'     => 1,
            'prev_next'    => true,
            'prev_text'    => sprintf( '<i></i> %1$s', __( 'Újabb Hírek', 'text-domain' ) ),
            'next_text'    => sprintf( '%1$s <i></i>', __( 'Régebbi Hírek', 'text-domain' ) ),
            'add_args'     => false,
            'add_fragment' => '',
        ) );
    ?>

                        <?php wp_reset_postdata(); ?>

                        <?php endif; ?>
                    </div>
                </div>

Unfortunately, this does not return any of the given articles.
I created this based on ACF’s documentation, but can’t figure out why it won’t give any results:

https://www.advancedcustomfields.com/resources/query-posts-custom-fields/

Echoing out $idcode gives me the result I want (this should be the value for $ceg), so that shouldn’t be the issue.

Thanks in advance!

0
Pbalazs89 4 weeks 0 Answers 7 views 0

Leave an answer