ACF + Wordpress, output of posts with meta key and meta value
<?php // параметры по умолчанию
$posts = get_posts( array(
'numberposts' => 0,
'category_name' => 'slider-main-loft-page',
'post_type' => 'post',
'meta_key' => 'where-page-post',
'meta_value' => get_page_link(),
'suppress_filters' => true, // подавление работы фильтров изменения SQL запроса
) );
foreach( $posts as $post ){
setup_postdata($post);
?>
<div class="slider-long-width-cont">
<?php the_content() ?>
</div>
<?php
}
wp_reset_postdata(); // сброс ?>
Using the AdvancedCustomFields plugin, I added a field with a choice of the page to which the post will go. The field returns a link in the format http://domain.com/link/ and it matches get_page_link ().
From the documentation for the get_posts function(): You can specify meta_key and meta_value, then you will get posts that have the specified metafield and whose value is equal to the specified value.
What am I doing wrong? I tried to specify http://domain.com/link/ in meta_value, but the posts were still not output.
UPD: If you change the field type from "Link to page" to "Text" and add a link to the post in plain text, then everything works. At the same time, the output of the fields is absolutely identical with different types.
1 answers
The "Link to Page" field type in Advanced Custom Fields actually displays the page link to the front, but it only stores the id in the database.
Was:
'meta_value' => get_page_link(),
Become:
'meta_value' => get_the_ID(),