I have created a custom field called "team member" with different labels to develop 7 different team member pages.
However, when I click on each of the member, they take me to a blank page with just header and footer. Looks like they are using the template single_Post.php.
How can I point the custom fields to a custom php template in the wordpress so that I can have one team member per page whenever I fill up the Team custom field in the back end.
<?php /* Template Name: Team */
get_header();
the_post();
$team_posts = get_posts( array(
'post_type' => 'team',
'posts_per_page' => 1, // Unlimited posts
) );
if ($team_posts):
?>
<div id="TeamBanner">
<?php
foreach($team_posts as $post):
setup_postdata($post);
$image = get_field('banner_image');
if( !empty($image) ):
?>
<img src= "<?php echo $image['url'];?>" alt="<?php echo $image['alt']; ?>"/>
<div id="innerbannerText" style="width:100%;">
<h1><?php the_field('member_name'); ?></h1>
<h3>
<i><?php the_field('member_subheading'); ?></i>
</h3>
<p> <span> <?php the_field('team_content'); ?> </span> </p>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
Jon,
In this case, there are a couple of things you need to be aware of
Firstly, from the query above
$team_posts = get_posts( array(
'post_type' => 'team',
'posts_per_page' => 1, // Unlimited posts
) );
Your custom post type is called team. So what you need to do is (following the guide here - https://developer.wordpress.org/themes/basics/template-hierarchy/) to rename your custom-teampage.php file to single-team.php
This should sort your problem out. However, you may receive a 404 error when you try to look at one of your team pages. If this happens - follow this guide here: https://wordpress.stackexchange.com/questions/202859/custom-post-type-pages-are-not-found
Hopefully this will solve your problem
Related
I have set up a feed in a larger page template the lists the most recent posts from a custom post type and belong to a custom taxonomy
e.g. (in this case) a feed listing the most recent video testimonials. (custom post type = testimonials, custom taxonomy = testimonials_cat, slug = video).
I want to add a link that says “view all video testimonials” which would link to a ‘taxonomies-testimonials_cat.php’ (that I’ve already created) displaying all video testimonials.
My question is how do I generate the link? And where do I put it?
From a design point of view I would like the link to be placed directly after section <h3>title</h3> (where i have marked in the code <?php GET_LINK_TO_ARCHIVE_PAGE ?>).
Thanks
Here is my code for the WP_Query loop and HTML:
<!-- VIDEO TESTIMONIALS -->
<div class="row"><div class="col-md-12"><h3><?php the_field('title_2'); ?></h3>
View all video testimonials...
</div></div>
<div class="row">
<!-- VIDEO ARGS -->
<?php
$args = array(
'post_type' => 'testimonials',
'tax_query' => array(
array(
'taxonomy' => 'testimonials_cat',
'field' => 'slug',
'terms' => 'video'
)),
'orderby' => 'date',
'posts_per_page' => 4
);
$videos = new WP_Query( $args ); ?>
<!-- VIDEO FEED -->
<?php if ( $videos->have_posts() ) : ?>
<?php while ( $videos->have_posts() ) : $videos->the_post(); ?>
<div class="post-wrapper testimonials video col-sm-3" id="post-<?php the_ID(); ?>">
<h2 class="post-title"><?php the_title(); ?></h2>
<?php the_field('video'); ?>
</div><!-- end of post wrapper -->
<?php endwhile; ?>
<!-- if no post found -->
<?php else: ?>
<div class="col-md-12"><h3><?php _e('Sorry, no posts matched your criteria.'); ?></h3></div>
<?php endif; wp_reset_query(); ?>
<!--/ end of WP loop -->
</div><!-- end of row -->
<hr>
I think you can use get_term_link( $term, $taxonomy ) function.
In your case, this should work:
<a href="<?php echo get_term_link( 'video', 'testimonials_cat' ); ?>">
View all video testimonials...
</a>
I am trying to show the most recent posts titles in the sidebar based on what category the post resides in. This code works great for a specific page template, but if I put this in the single.php file, I can only pull post titles from one category.
Is there a way to show post titles based on the category of the post?
<!-- BEGIN SIDEBAR -->
<div class="col-md-4 column blogsidebar">
<aside id="recent-posts-4" class="widget widget_recent_entries">
<h1 class="widget-title">Recent Articles</h1><hr>
<?php $my_query = new WP_Query('category_name=Blog&showposts=10'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); echo '<br>'; ?>
<a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?></a><br>
<?php echo word_count(get_the_excerpt(), '12'); ?>...<br>
<?php endwhile; ?><p></p>
</div>
<!-- END SIDEBAR -->
First get the category of the visible post, and then query with that.
$post_cat_ids = wp_get_object_terms( get_the_ID(), 'category', array('fields' => 'ids'));
Then on your query,
<?php
$my_query = new WP_Query( array(
'category__in' => $post_cat_ids,
'showposts' => 10
));
?>
So I've created a custom page template for my "Topics" Page.
What I want to do is add in some PHP to the custom page template my Topics page uses, to retrieve permalinks for the 3 most recent posts from a chosen category.
E.g.
(From post category 1)
--> Permalink for post 1
--> Permalink for post 2
--> Permalink for post 3
My code so far is as follows:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<ul>
<?php
$category_posts = new WP_Query('cat=consumer-trust&showposts=3');
while ($category_posts ->have_posts()) : $category_posts->the_post();?>
<li>
<a class="yourclass" href="<?php the_permalink(); ?>" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?> </a></li>
<?php endwhile; ?>
The problem, however, is that changing the cat in the WP_Query doesn't seem to make any difference. I've tried numbers and category names, and neither works.
Can anybody advise? This code will appear three times on the intended page, for three different categories.
use
query_posts( array ( 'category_name' => 'cat_name','meta_key'=>'_pr_date', 'orderby' => 'meta_value','order'=>'DESC') );
Thanks for all the help, I've managed to find an answer:
<?php global $post; // required
$args = array('category' => 18); // include category 18
$custom_posts = get_posts($args);
foreach($custom_posts as $post) : setup_postdata($post);
// put here what you want to appear for each post like:
//the title:
the_title();
endforeach;
?>
So I did my due diligence looking on here for an answer since this has come up a few times in the Treehouse forum, but found nothing related. I also tried to find a related topic on the acf site but that didn't give me the right info either. Hopefully you guys can help me out.
At the end of a tutorial on Treehouse, the instructions explain to add a few custom fields using ACF. He explains how to pull all of those in the code except on one crucial one.
We are supposed to create a checkbox field with the Field Label as Display on Homepage Slider and Field Name (or slug) as display_on_homepage. The idea is that we check this on each custom post entry that we want to display on the homepage slider, if you hadn't already guessed that.
Here's the code for the slider as it stands now.
<?php get_header('header.php'); ?>
</div>
<div id="featured" class="clearfix flexslider">
<ul class="slides">
<?php
$args = array(
'post_type' => 'work'
);
$the_query = new WP_Query( $args );
?>
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li style="background-color:<?php the_field( 'background_color' ); ?>;">
<div class="container">
<div class="grid_7">
<img src="<?php the_field( 'homepage_slider_image' ); ?>" alt="<?php the_title(); ?> Project Screenshot">
</div>
<div id="featured-info" class="grid_5 omega">
<h6>Featured Work</h6>
<h3><?php the_title(); ?></h3>
<p><?php the_field( 'description' ); ?></p>
<p><a class="btn blue" style="background-color: <?php the_field( 'button_color' ); ?>" href="<?php the_permalink(); ?>">View Project →</a></p>
</div>
</div>
</li>
<?php endwhile; endif; ?>
</ul>
</div>
I'm sure I need to pull some conditions in the args or even establish a different rule in my acf plugin, but I'm at a loss as to where to start with that can of worms. Thanks in advance for any help or advice. I'll be sure to forward this answer to the forum if I can get any assistance.
You'll want to add in an argument to your query for your custom field (meta field): http://codex.wordpress.org/Class_Reference/WP_Query
$args = array(
'post_type' => 'work',
'meta_key' =>'display_on_homepage',
'meta_value'=>'true'
);
The first answer is almost there, just missing a couple of commas :)
$args = array(
'post_type' => 'work',
'meta_key' =>'display_on_homepage',
'meta_value'=>'true'
);
This may be a basic question but i cant seem to find a correct solution.
In advanced custom fields I have set up a Field Group CD, in CD there are three fields, title, info, author and the group shows if the category = CD
Therefore when i make a new post with category CD I fill these three fields. There are 10 Posts in the CD categories.
Now the issue I am having is displaying all the posts on a page.
Here is the code I tried
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php query_posts( array( 'posts_per_page' => -1, 'cat' => '6', 'CD' => ( get_query_var('CD') ? get_query_var('CD') : 1 ), ));
if (have_posts()) {
while (have_posts()) {
the_post();
get_post_meta();
} // end while
} // end if
?>
<?php endwhile; endif; ?>
This returned an error Warning: Missing argument 1 for get_post_meta(), called in /Volumes/shared/Digital/_Websites/londonconchord/wp-content/themes/conchord/t-disc.php on line 25 and defined in /Volumes/shared/Digital/_Websites/londonconchord/wp-includes/post.php on line 1792
I tried a different attempt
<p><?php query_posts( 'cat=6' );
the_field('title');
the_field('info');
the_field('author'); ?></p>
I had more luck here as I was printing some information, however only the 1st post in the category and it kept repeating, i wanted all 10 posts and no repeat.
I think im close just looking for those final pointers
Thanks
My solution (Finally,) Hope this can help others
<?php
$args = array('cat' => 6);
$category_posts = new WP_Query($args);
if($category_posts->have_posts()) :
while($category_posts->have_posts()) :
$category_posts->the_post();
?>
<div class="article">
<div class="articleinfo">
<h3><?php the_field('title'); ?></h3>
<?php the_field('author'); ?>
<?php the_field('label'); ?>
</div>
<img src="<?php the_field('cd_image'); ?>" height="200" width="200" alt="cd-image" />
</div>
<?php
endwhile;
else:
?>
Oops, there are no posts.
<?php
endif;
?>
Loops through all posts and pulls the ACF i needed
Seems get_post_meta() has variables and your are missing it.
Like get_post_meta($var) expected but your are just calling get_post_meta(). Hope it helps.
You're not querying properly I don't think.
You need to grab the field
get_field('YOUR FIELD NAME') );
Then loop through and grab what you need as a subfield.
the_sub_field('YOUR SUB FIELD');
Example
<?php if(get_field('YOUR FIELD NAME')): while(has_sub_field('YOUR FIELD NAME')): ?>
<img class="logo" src="<?php the_sub_field('logo'); ?>" />
<h1><?php the_sub_field('title'); ?></h1>
<?php endwhile; endif; ?>
For an example. Hope this helps... let me know.
I couldn't get ether of the solutions above to work, thank you though guys for your input,
here is my solution so far
<h3><?php the_field('title', 475); ?></h3>
<?php the_field('info', 475); ?>
<?php the_field('author', 475); ?>
</div>
<img src="<?php the_field('cd_image', 475); ?>" height="200" width="200" alt="" />
Then I just repeated this and changed the id from 475 to others, now ive pulled in all the posts however the downfall is that any new posts i have to add in this code again.
Can i use a wp query to pull these 4 fields in a variable and then print that variable, then loop through the category until all posts are printed?