P
P
Pshkll2015-11-17 01:57:01
WordPress
Pshkll, 2015-11-17 01:57:01

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:
9b37cb77717441b3a89ba7101396a817.png
Then I created:
4e1410c2f0b94d6f962d0346bd903eea.png
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

1 answer(s)
P
Pavel Chesnokov, 2015-11-17
@Pshkll

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>';
        }
    }
}

PS In "Pods" for the link field there is a "Website" type, use it, not "Plane text".
Pods are (in my opinion) a great choice.
Good luck and be patient!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question