Answer the question
In order to leave comments, you need to log in
How to display a field in the code of any page using the Pods plugin?
Hello. Help me to understand.
Using the Pods plugin, I created a Pod:
Then I created:
How can I display the value of the link field on the front-page.php page or any other (header.php, footer.php, page.php ...)?
Answer the question
In order to leave comments, you need to log in
Your pictures do not match one another, the fields and their number are different. I am writing an example from the second picture, where I see the "page_title" field and the "link" field, and the "Pod" is called "site". The code will be something like this:
$params = array(
'limit' => -1, //Колличество записей, -1 = все.
//Для сложных запросов используем параметры
//Например:
//'orderby' => 'RAND()',
//'where' => 'link.meta_value = "vk.com"',
//'where' => 'xxx.meta_value IN ("xx", "yy") AND yyy.slug IN (' . $comma_separated . ')',
//Читайте тут:
//http://pods.io/docs/code/pods/find/
);
$mypod = pods( 'site', $params );
if ( $mypod->total() > 0 ) {
while ( $mypod->fetch() ) {
$id = $mypod->id();
//Далее можно использовать методы "WordPress":
$custom_link = get_post_meta( $id, 'link', true );
//Если убрать в конце "true" получите не значение поля, а массив с одним элементом.
//Это нужно для полей где может быть несколько значений, например несколько картинок.
//Или методы "Pods":
//$custom_link = $mypod->field('link');
//Проверяем полученные данные и выводим их:
if ($custom_link) {
echo '<a href="' . $custom_link . '">' . get_the_title( $id ) . '</a>';
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question