OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

WordPress - Display Custom Field on Post - Pull Post Title and URL

  • Thread starter Thread starter user2898224
  • Start date Start date
U

user2898224

Guest
Okay, I have the code pulling the custom fields URL and title of the url. Now I can't seem to get it to show the second featured blog. Here is the working code.

Code:
<?php $related = get_post_meta($post->ID, "Featured-Blog", $single=true);

        $related=explode(',',$related);
        $args = array_merge( array('post__in'  => $related, $wp_query->query ) );
        query_posts($args);
        if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

        <div id="<?php the_ID(); ?>">
            <a href="<?php the_permalink();?>"><p class="caption"><?php the_title(); ?></p></a>
        </div>

    <?php endwhile; else: ?>
    <p>no related</p>
    <?php endif; wp_reset_query();?>

This code example here produces two results, which is almost what I want. Which is caused by the foreach I believe. I do not want to use the code below, but I need to find a way to add the foreach I think to get it to list all of the featured-blogs if I have more than one.

Code:
<?php
  $custom_fields = get_post_custom($post_id); //Current post id
  $my_custom_field = $custom_fields['Featured-Blog']; //key name
  foreach ( $my_custom_field as $key => $url )
 echo $key ="<a href='".$url."'>TEST</a><br /><br /><br/>";
?>

Here is a screenshot showing my Custom Fields if it helps at all, and the results they are showing on the site. screenshot
<p>Okay, I have the code pulling the custom fields URL and title of the url. Now I can't seem to get it to show the second featured blog. Here is the working code.</p>

<pre><code><?php $related = get_post_meta($post->ID, "Featured-Blog", $single=true);

$related=explode(',',$related);
$args = array_merge( array('post__in' => $related, $wp_query->query ) );
query_posts($args);
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<div id="<?php the_ID(); ?>">
<a href="<?php the_permalink();?>"><p class="caption"><?php the_title(); ?></p></a>
</div>

<?php endwhile; else: ?>
<p>no related</p>
<?php endif; wp_reset_query();?>
</code></pre>

<p>This code example here produces two results, which is almost what I want. Which is caused by the foreach I believe. I do not want to use the code below, but I need to find a way to add the foreach I think to get it to list all of the featured-blogs if I have more than one.</p>

<pre><code><?php
$custom_fields = get_post_custom($post_id); //Current post id
$my_custom_field = $custom_fields['Featured-Blog']; //key name
foreach ( $my_custom_field as $key => $url )
echo $key ="<a href='".$url."'>TEST</a><br /><br /><br/>";
?>
</code></pre>

<p>Here is a screenshot showing my Custom Fields if it helps at all, and the results they are showing on the site. <a href="http://postimg.org/image/dvw2etgnb/" rel="nofollow">screenshot</a></p>
Continue reading...
 

Latest posts

ن
Replies
0
Views
1
نعمان منذر محمود الجميلي
ن
Top