Skip to content

Instantly share code, notes, and snippets.

<?php
//get the value for the relationship field
$related = $obj->field( 'company_staff' );
//loop through related field, creating links to their own pages
//only if there is anything to loop through
if ( ! empty( $related ) && is_array($related) ) {
$output = array();
foreach ( $related as $rel ) {
//get id for related user and put in id
//get name for related user and put in name
@axeldevo
axeldevo / gist:9917787
Created April 1, 2014 16:32
Current user's main title / multisite installation
<?php
switch_to_blog(1);
wp_start_object_cache();
global $current_user;
get_currentuserinfo();
$user = pods(‘user’, $current_user->ID);
echo '<p>' . $user->field(‘user_main’) . '</p>';
restore_current_blog();
wp_start_object_cache();
?>
@axeldevo
axeldevo / gist:9648855
Created March 19, 2014 19:02
Relationships using Advanced Content Types
<?php
//get the value for the relationship field
$related = $obj->field( 'company_investors' );
//loop through related field, creating links to their own pages
//only if there is anything to loop through
if ( ! empty( $related ) && is_array($related) ) {
$output = array();
foreach ( $related as $rel ) {
//get id for related investor and put in id
//get name for related investor and put in name
@axeldevo
axeldevo / gist:9625734
Created March 18, 2014 18:01
bi-directional relationship URL 2
<?php
$params = array(
'where' => "investor_companies.ID = " . get_the_ID(),
'limit' => -1 // Return all rows
);
$investors = pods( 'investor', $params );
if ( 0 < $investors->total() ) {
while ( $investors->fetch() ) {
$elements[] = '<a href="' . $investors->display( 'permalink' ) . '">' . $investors->display( 'investor_name' ) .'</a>';
} echo implode(', ', $elements);}
@axeldevo
axeldevo / gist:9625623
Created March 18, 2014 17:56
Bi-directional relationship URL
<?php
//get the value for the relationship field
$related = $obj->field( 'company_investors' );
//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' ];