Hopfully I can explain this, I'm confusing myself now.
I have Template called 'Landing' that is the template for a number of different pages in Wordpress.
Each of the pages using this template will contain different blocks of information.
These blocks contain a title, an image, text and a link, I'm calling them Content_Widgets, they are not Widgets in the Wordpress sense.
My Content_Widgets are each posts and I have created a custom post type called Content_Widget.
Now I need to load the correct posts on the correct page.
I thought I could do this by having a category on the page in Wordpress and then the same category on the post for that page.
So it would be like load the post that have a category the same as this page.
Is this a good way to load the correct post on the correct page?
So this is the code I'm using but it's not outputting anything.(I'm using Advanced Custom Fields in the Custom post type.)
The correct category name outputs in the h1 but nothing else.
Anyone have any ideas why this isn't working, or is this the wrong way to do this??
<div id="contentWidgets">
<?php
// get category name for page
$cat = get_the_category($post->ID);
$catName = $cat[0]->name;
echo $catName;
$content_args = array(
'post_type' => 'Content_Widget',
'category_name' => $catName
);
$content_loop = new WP_Query($content_args);
if($content_loop->have_posts()):
while($content_loop->have_posts()):
$content_loop->the_post();
$linkImg = get_field('image');
$txt = get_field('text');
$link = get_field('link');
?>
<h1><?php echo $catName;?></h1>
<dl>
<dt><?php the_title(); ?></dt>
<dd><img src="<?php echo $linkImg; ?>" alt=""></dd>
<dd><?php echo $txt; ?></dd>
<dd><a href="<?php $link; ?>">Find out more</a></dd>
</dl>
<?php
endwhile;
endif;
wp_reset_postdata();
?>
</div><!--contentWidgets-->
$catName
and$cat_Name
, is that a typo here?register_post_type
: $post_type (max. 20 characters, can not contain capital letters or spaces)