V
V
vector20142020-04-17 14:57:44
WordPress
vector2014, 2020-04-17 14:57:44

How to get the value of the field of the record on which the function is loaded?

How to get the value of the field of the record on which the function is loaded. In function.php there is an ajax record filter code - I need to filter records by the value of an additional record field, which should be automatically obtained when loading the function on this record. Here is a piece of code

add_action('wp_ajax_myfilter', 'misha_filter_function'); // wp_ajax_{ACTION HERE} 
add_action('wp_ajax_nopriv_myfilter', 'misha_filter_function');
 
function misha_filter_function(){
  if( isset( $_POST['featured_image'] ) && $_POST['featured_image'] == 'on' )

    $keyg = get_post_field('банкс');
    $args['meta_query'][] = array(
        array(
            'key' => 'банкс',
            'value' => $keyg,
        ),
            array(
            'key' => 'кэшбэк',
            'value' => 'Нет',
        )
    );
  $query = new WP_Query( $args );

  if( $query->have_posts() ) :
    while( $query->have_posts() ): $query->the_post();
  $url = wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) );


It is required to receive value of a field "banks" - but it is impossible in any way. There is another option - get the id of the record in which the function is loaded and then get the values ​​\u200b\u200bof its field like this
$keyg = get_post_field('банкс',3948);
    $args['meta_query'][] = array(
        array(
            'key' => 'банкс',
            'value' => $keyg,
        ),
            array(
            'key' => 'кэшбэк',
            'value' => 'Нет',
        )
    );
  $query = new WP_Query( $args );

= but I don't have enough knowledge to get the post id - I just can't insert the code from the manuals. Asking for help from those in the know...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
KingAnton, 2020-04-17
@KingAnton

I don't understand what you need.
You can try this in a loop:
$keyg = get_post_field( 'банкс', get_the_ID() );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question