Answer the question
In order to leave comments, you need to log in
Why doesn't WordPress WP_Query() output links from the ACF field?
In WordPress ACF there is a field for pages of the type "Link to page" (page_link) I try to filter all pages where a certain link is specified and nothing happens. I write code like this:
$args = array(
'post_type' => 'page',
'meta_query' => array(
array(
'key' => 'razmer',
'value' => 'https://домен/400mmx40mm/',
)
)
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
} else{
echo 'Ничего';
}
Answer the question
In order to leave comments, you need to log in
The "page_link" type field stores the page ID and not its URL (page exception in the Archive).
UPDATE:
$post_id = url_to_postid('https://домен/400mmx40mm/');
$args = array(
'post_type' => 'page',
'meta_query' => array(
array(
'key' => 'razmer',
'value' => $post_id,
)
)
);
Thanks yarovikov and Pavel Chesnokov
Should have written:
$args = array(
'post_type' => 'page',
'meta_query' => array(
array(
'key' => 'razmer',
'value' => 289,
'compare' => 'LIKE'
)
)
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
} else{
echo 'Ничего';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question