
What do you want to display? You can just use the post object as is like this:
<?php
$postobject = get_sub_field('nameofyourpostobjectdropdownfield');
$postobject->post_title //post title
$postURL = get_permalink($postobject->ID); //URL
apply_filters('the_content', $postobject->post_content); //The post content formatted
$postdate->post_date //post publish date
?>
And there’s more if you do a print_r($postobject); and take a look 🙂

Hi!
First off, move wp_reset_postdata(); right under the endforeach; in your related posts loop.. that should fix the error with the incorrect ID.
Secondly.. there doesn’t seem to be a default archive link for posts if you don’t include a date or category tag (like http://www.demo.com/2012/). I honestly cant think of a smooth way to solve this the way it’s set up at the moment.. If I where you I’d either rethink it all or id create categories thats named the same as the companies but with a permalink of something like companyname-cat and assign the posts to them as well. That way you could just put this for the readmore link:
<?php
$cat = get_category_by_slug($post->slug.'-cat');
$catlink = get_category_link($cat->term_id);
?>
<a href="<?php echo $catlink; ?>">View all</a>
then you can check in archive.php if it’s trying to display a category with
if(is_cat()){
//the archive is displaying posts from a category
}
If this solution doesn’t work you could create a custom taxonomy and assign it to the posts (besides categories and tags) and use them instead and change the functions accordingly..
<?php
$cat = get_term_by('slug, '$post->slug.'-cat', 'your-taxonomy-slugname');
$catlink = get_category_link($cat->term_id);
?>
<a href="<?php echo $catlink; ?>">View all</a>
and:
if(is_tax()){
//the archive is displaying a term from a taxoonomy
}

I think your theme is all wack.. getting loop issues and stuff all the time.
I don’t think thats the actual link but rather the a-tag is linked with just /?company=240 and since there’s nothing before that the link appears to go to that URL (which is the same as the one your on right?).
So that means get_post_type_archive_link isn’t working. What version of WP do you run? You’ll need to have it up to date (or atleast 3.1) for the function to work.

ahaaa okay.
Well if you try to echo out the second row what do you get?

Hello again Nataliette.
With my previous solution, did you create a loop inside the if-statement for when you have company posts?
<?php get_header(); ?>
<?php // if is a link to Read More from company single related post
if(isset($_GET['company'])){ ?>
<?php
$company_id = $_GET['company'];
Show all related posts from the company's singular page.
$doctors = get_posts(array(
'post_type' => 'doctor',
'meta_query' => array(
array(
'key' => 'location', // name of custom field
'value' => '"' . $company_id . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
));
?>
<?php if( $doctors ): ?>
//ETC. This is not a full loop
?>
<?php } else { ?>
<?php while ( have_posts() ) : the_post(); // The Loop ?>
<?php get_template_part( 'content','excerpt' ); ?>
<?php endwhile; ?>
<?php } ?>
<?php get_footer(); ?>

Great! You learn something new everyday when coding, that’s what makes it fun 😉
No problem Dadra, glad to help out!

ahhhh!
Actually your code should work but you need to change it to this:
<?php
$selected = get_field('q_and_a_category_select');
$args=array(
'post_type' => 'q-and-a',
'q_and_a_category' => "$selected" //the slug for the custom taxonomy term
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php the_title(); ?>
<?php endwhile; }?>
<?php wp_reset_query(); ?>
you could put the get_field directly in the array but I think this looks more structured 🙂

Ah okay..
well I’m not unfamiliar to that approach to be honest since I’ve been in the same seat.. Altho you know you could add the custom content to the terms edit pages in admin and display them in the wp archive. But I guess that’s not too user friendly and especially if you have a lot of info to be put in.
It’s a good idea to name the custom field differently than the taxonomy since it can cause issues.. so thats good!
May I ask then how the user selects which terms the post should be connected to? Are you using acf taxonomy field?

No worries @nataliette 🙂
Glad to help, keep up the good work!
Here’s actual proof that I’m awesome (if you have a spotify account):
http://open.spotify.com/track/3RIkLl4v8Ex27OpIwTZSIu

Hi Nataliette,
If your get_field function runs after the first loop you could simply add the post id to a variable inside the loop and use that. Like:
$post_id = get_the_ID();
Then use it in the get_field:
get_field('banner_selection', $post_id);

Hi!
What you’re trying to do actually already exists in WP. Since you’ve created a custom post type with a custom taxonomy there’s an archive (provided that you have set archive to true when creating the post type). So you should be able to reach each taxonomys posts by having an url something like this:
http://www.myurl.com/q_and_a_category/design
Wordpress will use archive.php per default to display these but if you require customization and dont want to affect the regular archives you can create a new template:
taxonomy-q_and_a_category.php
If you want specific templates for the terms you can do:
taxonomy-q_and_a_category-design.php
etc.
If you still want to do it in the way you’ve done so far (i would not recommend it) you need to replace the meta-query with a tax-query since the taxonomys terms are not meta values..
Read more here: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

Hi Synergy..
First of, codoes on using rofl as a way of debugging.. gotta remember that ;9
I can’t help you with most of this but I do think that your jquery error is due to the latest jquery. in the next version of ACF it says on the do to:
JS: Major update to conditional logic JS to allow for repeater sub fields – will also require an update to the repeater field add-on
So I think Elliot will have that fixed by then. In the meantime if it really screws with you it wouldn’t be the end to revert back to 1.8.2 (i think thats the last one). I’ve had to do it myself on some occasions..

Alright 🙂
Altho this:
<?php
if (get_field('sub_specialty') != '') { ?>
says “do stuff if this field is not an empty string”
while this (in my code):
<?php if (get_field('sub_specialty')) { //Sub speciality ?>
says “do stuff if this field has any values”. So you should still use that instead 🙂 Its pretty much a shorthand.. say if you want to apply something when there’s no field it could say this:
<?php if (!get_field('sub_specialty')) { //Sub speciality ?>

Hi! Okay well I don’t know how your code looked before that was just to show you how to retrieve the name rather than just the id 🙂
Your code seems a bit excessive and unsemantic. Is there any reason it couldn’t look like this?
<?php if (get_field('sub_specialty')) { //Sub speciality ?>
<strong>Sub specialty.:</strong>
<ul>
<?php $terms = get_field('sub_specialty'); ?>
<?php foreach ($terms as $term){ ?>
<li><a href="<?php echo $term->slug; ?>" name="<?php $term->slug; ?>" alt="<?php $term->name; ?>"><?php echo $term->name; ?></a></li>
<?php } ?>
</ul>
<?php } ?>
There’s no unnecessary functions running, the else-statement was removed, the if statement is changed to be simpler, name was corrected and the html is semantically correct since it’s now an unordered list instead of links with an inline break. 🙂
Happy coding

ah..
On the field in admin you can select wether you want it to return the term ID or the term object.. Switch it over to term object then do this where you want the name:
<?php echo $term->name; ?>
This is based on that in your foreach loop you call the single term $term. So just switch that out if you use something else 🙂

Sorry I have no idea.. but if it’s just about the type of page you’ve linked it’s either single.php or page.php depending on if its a post or page.. (it could also be a different file if the page is using a custom template). Some themes also use a different file for the loop in which most content is created and this is usually called loop.php.
So you see why its hard to help out without actually doing the work and that’s a little too much work for me I’m afraid 🙂


if you change the return of your image field (in admin) to url it’ll work.. 🙂

it’s either that or you’ll have to check if the price has decimals or not when adding them to your theme files and if not add .00 to the field value 🙂
(if you go this route I highly suggest you create a function for it in functions.php and call it on each place in the theme files instead of writing the same code repeatedly)

Hi!
When you change the theme your ACF fields are still there in the admin as well as their values on pages, posts etc.. However the new theme will most likely not display the fields since there’s no code for them in the theme-files.
You wont have to do anything to ACF but rather add your fields to the theme-files in the way they where added to your previous theme. If you do not have the skills to do so you’ll either have to stick to your old theme or hire someone to fix the new one!

Alrightie then.. your code is extremely overdoing it!
You’ll want something like this:
<?php
$args = array( 'hide_empty' => '0');
$categories = get_categories($args);
if($categories){
echo '<ul>';
foreach($categories as $category) {
echo '<li>';
$image = get_field('nameofimagefield', 'category_'.$category->term_id);
echo '<img src="' . $image . ' />'; //change depending on the return value of the image field
echo '<span class="cat-title">' . $category->name . '</span>';
echo '<span class="cat-subtitle">' . get_field('nameofsubtitlefield', 'category_'.$category->term_id) . '</span>';
echo '<span class="cat-description">' . $category->description . '</span>';
echo '</li>';
}
echo '</ul>';
}
?>
dont forget to change the fieldnames

Okay,
Then to answer your question no, you cant have the one layout be chosen per default when adding a flexible field.. Since it would be pretty much the same as repeaterfield except less effective. I strongly suggest that if this is an issue for you just purchase the repeater field addon 🙂 Trust me, it’s well worth it!

just to make sure..
Do you have the field set up to both regular posts as well as company posts?
Also check if there’s a difference in the two files for if the code is inside or outside the loop.

Hi!
Do you mean that departments are a custom post type?
I dont understand how the setup is.. 🙂

Hi Tom!
What you got there is a little strange…
The logic you have says:
Get all regular categories, loop through them and in each category fetch the current posts categories then get just the last category object and fetch the custom field of that category.
What exactly are you trying to do? Do you want to display the current posts categories or do you want to display all categories as links(or without links)?
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.