• Resolved jmuller777

    (@jmuller777)


    Hi,

    I am struggling for hours through the documentation trying to implement something that should be very simple, but to a non technical person like me its like a monster!

    I have two pods as custom post types:

    1) Books
    2) Authors

    In the books post type i have a relationship custom field related to the authors custom post type.

    In the authors custom post type i have a relationship custom field related to the books custom post type.

    Both as bi-derectional.

    I already know hot to display the other custom fields, what i dont know is how to get the title and the permalink of the author of each book into each books custom post type and the list of the books assigned to each author into each authors custom post type.

    For instance:

    <?php
    add_action( 'genesis_before_entry_content', 'do_book_fields' );
    function do_book_fields() {
    //get Pods object for current post
    $books = pods( 'books', get_the_id() );
    $book_image = $books->display( 'book_image' );
    
    //*adds the book image if its setted
    if ($book_image) {?>
          <dl><dt >Image:</dt>
          <dd><a itemprop="url" href="<?php echo get_permalink( $post->ID ); //*adds the url of the book?>" title="Book: <?php the_title(); ?> writen by <?php HOW TO GET THE TITLE AND URL OF THE AUTHOR HERE  ?>"><img itemprop="image" src="<?php echo $ibook_image ?>" alt="Book <?php the_title(); ?>" title="<?php the_title(); ?>"/></a></dd></dl>
    
    <?php }}

    I need a way to get the authors pages titles and urls to use inside the books pages and vice versa, and i would love if i could do it in a similar fashion as the other filds…

    I tried to follow this tutorial: https://pods.io/tutorials/get-values-from-a-custom-relationship-field/ several times with no success at all.

    Could someone please help me out on this?

    Regards.

    https://www.ads-software.com/plugins/pods/

Viewing 5 replies - 16 through 20 (of 20 total)
  • Thread Starter jmuller777

    (@jmuller777)

    Sorry, but i dont have a gist account.

    Here is the synthesis environment where the error is occurring:

    WordPress Version: 3.9.1
    PHP Version: 5.3.10-1ubuntu3.11
    MySQL Version: 5.5.37
    Server Software: Apache/2.2.22 (Ubuntu)
    Your User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36
    Session Save Path: /var/lib/php5
    Session Save Path Exists: Yes
    Session Save Path Writeable: Yes
    Session Max Lifetime: 1440\
    WPDB Prefix: wp_
    WP Multisite Mode: No
    WP Memory Limit: 40M
    Pods Network-Wide Activated: No
    Pods Install Location: /var/www/fuvestibular.com.br/wp-content/plugins/pods/
    Pods Tableless Mode Activated: No
    Pods Light Mode Activated: No
    Currently Active Theme: Fuvestibular
    Thread Starter jmuller777

    (@jmuller777)

    An here is the wordpress install i have in hostgator, where the code works perfectly:

    WordPress Version: 3.9.1
    PHP Version: 5.2.17
    MySQL Version: 5.5.33
    Server Software: Apache
    Your User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36
    Session Save Path: /tmp
    Session Save Path Exists: Yes
    Session Save Path Writeable: Yes
    Session Max Lifetime: 1440
    WPDB Prefix: wp_
    WP Multisite Mode: No
    WP Memory Limit: 40M
    Pods Network-Wide Activated: No
    Pods Install Location: /home1/denrrou/public_html/denrrou.com.br/wp-content/plugins/pods/
    Pods Tableless Mode Activated: No
    Pods Light Mode Activated: No
    Currently Active Theme: Lifestyle Pro Theme

    Email me: [email protected]

    and if you want, i can give you access to both environments.

    Thanks for your patience.

    Plugin Contributor Josh Pollock

    (@shelob9)

    Thank you for this info. It’s not showing me anything interesting, but it was worth trying. Normally you don’t think of HostGator as being the more compatible host.

    We need to get more information from Synthesis about why this isn’t working. Can you please reply to that ticket and tell them that we are not using either of those functions and that they can feel free to contact me directly ([email protected]) to discuss other restrictions they have in place that may be causing this issue.

    Thread Starter jmuller777

    (@jmuller777)

    They said on their side everything is ok,

    They also got rid of those errors, but now i get no errors nor any type of output as a result of the relationship field.

    I am trying to use this code:

    <?php
    //*Adds book's fields
    add_action( 'genesis_before_entry_content', 'do_book_fields' );
    function do_book_fields() {  
    
    //get Pods object for current post
    $pod = pods( 'book', get_the_id() );
    $book_image = $pod->display( 'book_image' );
    
    //*adds the book image if its setted
    if ($book_image) {?>
         <dl><dt>Image:</dt>
          <dd><a href="<?php echo get_permalink( $post->ID ); ?>" title="<?php the_title(); ?>"><img src="<?php echo $book_image ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /></a></dd></dl>
    
    <?php //get author post title as link
    //get the value for the relationship field
    	$related = $pod->field( 'book_author' );
    	//loop through related field, creating links to their own pages
    	//only if there is anything to loop through
    	if ( ! empty( $related ) ) {
    		foreach ( $related as $rel ) {
    			//get id for related post and put in ID
    			//for advanced content types use $id = $rel[ 'id' ];
    			$id = $rel[ 'ID' ];
    			//show the related post name as link
    			echo '<a href="'.get_permalink($id).'">'.get_the_title( $id ).'</a>';
    
    		} //end of foreach
    	} //endif ! empty ( $related )
    
    var_dump( get_the_id() );
    $pod = pods( 'book', get_the_id() );
    var_Dump( $pod->id() );
    
     }}
    
    genesis();

    The custom field assigned to the book image is working properly, as you can see here:https://fuvestibular.com.br/book/book-test/ but theres no output for the related post type author.

    I putted the The var_Dump just to see what it shows, and it is this: int(3216) int(3216)

    At least theres no erros anymore….

    Any thought on this?

    Plugin Contributor Josh Pollock

    (@shelob9)

    I’m going to reply to that email from their support momentarily. I think they are misunderstanding the issue or trying to punt. I’d like to work with them to figure out a way around this issue if possible. This is definitely not a problem we have with other managed hosts.

Viewing 5 replies - 16 through 20 (of 20 total)
  • The topic ‘Get The Title and Permalink of a post From Relationship Field’ is closed to new replies.