Support

Account

Home Forums General Issues Advance Custom Fields Get Custom Field Values of Posts in the Page

Unread

Advance Custom Fields Get Custom Field Values of Posts in the Page

  • I am new to wordpress and Advance Custom field Plugins, I need to get all the custom field value of the type=”POST” in the Custom page Template in wordpress, by getting that value i have to do some functions with the value and i need to pass that value in below code to retrieve Posts

    For example here is the code

    One of the custom field in My post which i need to retrieve is ‘subject_id’ So ‘subject_id’ value will be something like this “CS2360”

    So i need do function like $demo=substr((subject_id_vaue_here),0,2); where i ll be getting the value as “CS” so i need to pass the $demo in below array

    <?php
    $args = array(
        'numberposts' => -1,
        'post_type' => 'post',
        'meta_query' => array(
            'relation' => 'AND',
            array(
    
                'key' => 'subject_code',
                'value' => $demo,
                'compare' => '='
            ),
                array(
                'key' => 'categories',
                'value' => get_field( "sel_categories" ),
                'compare' => '='
            )
        )
    );
    
    $the_query = new WP_Query( $args );
    
    ?>
    <?php if( $the_query->have_posts() ): ?>
        <ul>
        <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
            <li>
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            </li>
        <?php endwhile; ?>
        </ul>
    <?php endif; ?>
    
    <?php wp_reset_query(); ?>

    Note: I am retrieving the value from the post to the page, so i do no how to select

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.