The href value comes from the_permalink(), which is dependent on the standard Loop to return the proper value. If you are not running a standard loop, that will explain the bad values. The value returned is filtered through ‘post_link’. This is another reason the value can get corrupted. It’s also the way to fix improper links.
There’s also the ‘the_content_more_link’ filter which returns the entire read more HTML: anchor tags, href, link text, and all.
Because of your unusual scheme, I’m not exactly sure how to determine the proper link. It should be what ever shows up under the title of the post(or article) edit screen. The post object is passed to ‘post_link’ callbacks, so there should be some way of constructing a proper link.
Hey bcworkz, I understand you in theory, but I’m relatively new to WP and custom themes. Here’s the code block pulling in the articles, including the custom “feature on home page” for the CPT of articles:
<div id="article-left">
<ul>
<?php
$args = array(
'post_type' => array('slideshow','article'),
'posts_per_page' => 3,
'meta_query' => array(
array(
'key' => 'feature_on_home_page', // name of custom field
'value' => '1',
)
),
);
?>
<?php $loop = new WP_Query( $args ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); $cats = get_the_category(); $cat_name = $cats[0]->name; ?>
<li>
<a href="<?php the_permalink() ?>">
<article>
<header>
<h3 class="dark-underline-text"><u><?php echo $cat_name?></u></h3>
<div class="date"><?php the_time('m/d/y') ?></div>
</header>
<h1><?php the_title(); ?></h1>
<div class="article-content-style">
<?php if( get_field('teaser_text') ):
echo get_field('teaser_text');
elseif( !get_field('teaser_text') ): ?>
<?php
$stringContent = get_field('content');
$stringspace = str_replace(" ","",$stringContent);
$slength = strlen($stringspace);
if ($slength > 180):
$shorten = substr($stringContent, 0, 180);
$strip = strip_tags($shorten);
echo $strip . '...'; ?>
<?php else: ?>
<?php echo get_field('content'); ?>
<?php endif ?>
<?php endif; ?>
</div>
<span>Continue Reading</span>
</article>
</a>
</li>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</li>
</ul>
<a href="/blog?filter=" class="more-post"><span>See More Posts</span></a>
</div>
When you mention the URL being what’s shows up under the title of the post/article edit screen, I assume you mean from the admin section, correct? Here’s the link generated when editing an article that’s present on the homepage from the admin section:
/wp-admin/post.php?post=9229&action=edit
That same article, on the front end, produces this URL when clicked:
/article/know-your-rights/
If you have a moment and could share your thoughts on this, it would help me a lot.
Thanks.
Yeah, I meant the admin section, though I didn’t mean the edit page link. What I did mean doesn’t matter any more because I had the wrong kind of link in mind. After looking at your template code I understand what your problem is. What I don’t know is exactly what posts are supposed to appear after following the See More Posts link. Still only articles and slideshows? (I’m going to use the generic ‘posts’ term for these, since they are still a type of post) The more posts are no longer with the ‘feature_on_home_page’ custom field I presume. Are the posts with this field to be excluded on the following pages or not? Just these three or all such posts?
You said there are 6 regions. Are the additional posts in any region or are they to be restricted by region? If so, what determines what region a post is for? Is WP installed in the public root folder of your domain or a sub-folder? If sub-folder, what’s the path from root to WP? Is this path used for the WP address in settings or is there some sort of symlink?
All these questions are because you will likely need more than just a correct link, there will likely need to be custom code to adjust the default query to meet your needs. Are you able to create a child theme or is your theme already installed as a child theme? If a child, is it a custom child that will not be updated or a commercial child that could be updated?
Hey bcworkz, first off thank you for such detailed responses, I greatly appreciate it. I haven’t responded until now because I needed to do some searching of the issue. Finally it became clear that the CPT’s were not recognizing that they had a category assigned to them, even though it was an option that was selected to use the WP-core categories with the CPT’s as there was no new taxonomy created to work with the CPT’s.
I found a fix from the plugin author, he sent me to this link:
http://docs.pluginize.com/article/17-post-types-in-category-tag-archives
Once I added that to my functions.php it responded by allowing me to pull up the CPT archives which is what I was trying to do.
Again, thank you for such detailed assistance.