Custom Posts not showing in archive page - php

I currently have a custom post type of Episode with a taxonomy of podcast. When i run the following loop on my archive page i am seeing that I have 149 posts
<?php
$args2 = array(
'posts_per_page' => 1000,
'post_type' => 'episode',
'podcast' => 'my-episodes',
'post_status' => 'publish'
);
$posts = get_posts($args2);
$count = count($posts);
echo $count;
?>
However, when I'm running this variation of the loop on my archive.php file (copied from the wordpress.org page), i am only getting 130 posts
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<small><?php the_time('F jS, Y'); ?> by <?php the_author_posts_link(); ?></small>
<div class="entry">
<?php the_content(); ?>
</div>
<p class="postmetadata"><?php _e( 'Posted in' ); ?> <?php the_category( ', ' ); ?></p>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
The loop is saying that my most recent entry was from the 5th, however i have been creating posts on a regular basis over the last few days. Are there any tests I can run to see why the most recent posts are not showing up on the archive page?

Your code appears to be correct. Double check that the posts that are missing are published and not set as a draft/saved. Also check that your custom taxonomy and post types are correct for the query you are running.

After reviewing the dashboard of the site per the recommendation of Tom here is what I was able to find
The site has a plugin called WPML activated. This allows the site to create content in multiple languages.
When the plugin is initially activated, it will ask for the site's native language and apply that to the existing posts and custom posts. This way if you were on an englsih version of the site you would see content ABC while on a spanish version you would see content XYZ.
There is a separate section inside of a custom post that allows you to make said custom post translatable. If this is not checked then your custom post will not display on any version of the site. The reason being (at least in my 5 minutes of research) is that because there is no language specified, it will not load on the language specific versions of the site
I have done two things to fix this:
I have added the ability to make the custom post translatable,
There is a setting that will allow you to display all content that is not translated on any version of the site as opposed to not displaying any content
Thank you everyone for your help.

Related

Configure Widget Logic to display related data using PHP

I have installed Widget Logic on a Wordpress site. Using is_single('this') it correctly displays the widget on the page. But, I need
'this' to be a variable and match another variable.
What I'm looking for is the PHP equivalent of a SQL "where" clause that will match one field to another. Select x from y where a=b;
I have posts that represent a "Location" - could be London, Paris, Munich.
I have posts that represent "Services" and can be filtered by location.
I have a widget that displays available services.
I want to dynamically filter what is displayed by the widget according to the location. If I have a Munich post, only those services available in Munich are displayed in the widget and only those services available in London are displayed on the London page.
I've tried setting Widget Logic to about 20 variations of 'field1'=='field2' or
$field1==$field2 and is_??(??) / in_??(??) No joy.
Maybe I have the syntax wrong? or using the wrong WP conditional tag?
Using Widget Logic for this didn't work out. The following runs in a PHP Text box widget on the WordPress page
$fish is the title of the post being displayed (e.g., London)
The related posts all have a 'meta-value' that includes the location (e.g., London)
<?php
$fish = get_queried_object_id();
if ('$fish' != null ) {
query_posts (array ('post_type' => array('accommodation'), 'meta_value' => $fish,
'orderby' => 'asc', 'showposts' => 3) );
if (have_posts()) : while (have_posts()) : the_post();?>
<h4><a href="<?php the_permalink() ?>">
<?php the_post_thumbnail( 'thumbnail'); ?>
<?php the_title(); ?></a></h4>
<?php endwhile;
endif;
} else {
echo "why is this here?";
}
?>

in_caterogy won't show after changing publishing date/time

Wordpress is behaving really strange here, beyond my understanding!
So having this 4 posts:
And this is how I show them on my site:
As you can see, it only shows 3 posts from the 'Events' category. This is right! See code:
if (have_posts())
{
while (have_posts()) : the_post();
if (in_category( 'Events' )) {
$haveEvents = true;
**if ($eventCount < 3) {**
$eventCount++;
?>
<div class="event-tile">
<div class="event-tile-content">
<h3><?php the_title(); ?></h3>
<h4><?php the_time('F jS, Y'); ?></h4>
Lees meer
</div>
</div>
<?php
}
}
endwhile;
}
I also have some other categories en thereby I use multiple have_posts loops for showing the post from each category.
Now after I added some new posts for each category, the 'Event' posts where gone. I tested like an hour or so, and I found the problem, for some reason the loop have troubles to show 'older' posts (belonging to the 'events' category).
Here Ill demonstrate what I mean:
Changed the 'published' time, so the posts was the 'oldest':
After committing this change, the post was gone..
I don't understand this strange behaviour from Wordpress.
As the code shows;
loop trow posts
If post in category 'Event' go on ->
if 'eventCount' smaller than 3 -> show
'eventCount'++
Did I made a mistake? Is wordpress buggy here?

how to get the posts from my index page to someother pages(like blog) in WordPress

i am beginner to WordPress, i have created the index.php it automatically shows my posts.. but i wanna posts to show also in another php file like blog.php.. how can i retrieve the same posts which is shown in index.php.........
The scenario is, i am developing theme for http://themeforest.net show that i wanna make some features in my blog page like without sidebar, left sidebar, right sidebar... but my home(index.php) contains posts.. whenever i starts new page with same coding(like blog.php), it doesn't show the index.php 's posts..
This sample piece of code retrieves 3 posts from categpry id 4
<?php
$args = array( 'numberposts' => 3, 'order'=> 'DESC', 'orderby' => 'post_date', 'category' => 4 );
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post);
$a= get_the_date();
?>
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?></p>
<?php endforeach; ?>
Refer the WordPress documentation http://codex.wordpress.org/The_Loop
it contain different example how to display post include or exclude post from specific categories etc..

Create a Custom WordPress Page with Post titles

I am trying to create a custom WordPress page that will contain only the links to all my post titles, divided on 4 column. I am also using Bootstrap with WordPress.
I created the php file, created a new page with her page atribute, but the post titles don't display.
This is the code i used:
<?php
/**
* The template used for displaying page content in questions.php
*
* #package fellasladies
*/
?>
<?php
<article id="post-<?php the_ID(); ?>" <?php post_class('col-md-4 col-sm-4 pbox'); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<?php the_content(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'fellasladies' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<?php edit_post_link( __( 'Edit', 'fellasladies' ), '<footer class="entry-meta"><span class="edit-link">', '</span></footer>' ); ?>
</article><!-- #post-## -->
I really appreciate your help! Thanks
You'll need to start by creating a Query which fills an array with the posts you want to iterate. Read about the get_posts() function in WordPress.
Here's an example. Note that we can't use functions which are meant to be used "in the loop" such as the_title() or the_content(). We must specify the post_id for each iteration. We should not modify the main query for situations such as this.
// the arguments for the get_posts() function
$args = array(
'post_type' => 'post', // get posts int he "post" post_type
'posts_per_page' => -1 // this means the array will be filled with all posts
);
$my_posts = get_posts($args);
// now we'll iterate the posts
foreach ( $my_posts as $p ) {
// a title
echo get_the_title($p->ID);
// the link
echo get_permalink($p->ID);
// a custom field value
echo get_post_meta($p->ID,'custom_field_key',true);
}
Theming what happens inside each iteration is up to you.
Good luck! :)
I encourage you to go read about Page Templates on Wordpress Codex, that could help you a lot!
Pages are one of WordPress's built-in Post Types. You'll probably want most of your website Pages to look about the same. Sometimes, though, you may need a specific Page, or a group of Pages, to display or behave differently. This is easily accomplished with Page Templates.
It seems that you have a <?php useless. You also don't define your template's name, which is required.

Wordpress custom field only displaying 10 posts

I've used wordpress Advanced Custom Fields plugin to make my portfolio page. I've setup fields for the image, title, category and a yes/no for weather the project is featured.
My code for the project page is as follows:
<?php
$args = array(
'post_type' => 'project'
);
$query = new WP_Query( $args );
?>
<?php Starkers_Utilities::get_template_parts( array( 'parts/shared/html-header', 'parts/shared/header' ) ); ?>
<h1 class="lead"><?php the_title(); ?></h1>
<div id="triggers">
<strong>Filter:</strong>
<span id="filterDouble">Filter All</span>
<span id="filter1">Filter 1</span>
<span id="filter2">Filter 2</span>
</div>
<ul id="gallery" class="group">
<?php if ( have_posts() ) while ( $query->have_posts() ) : $query->the_post(); ?>
<li class="gallery_image" data-id="id-" data-type="<?php the_field('project_category')?>">
<a rel="prettyPhoto[gallery]" class="zoom" href="<?php echo the_field('image') ?>">
<img class="mag" src="<?php bloginfo('template_url'); ?>/imgs/mag.png"/><div class="thumb_bg"></div>
<?php the_post_thumbnail('portfolio'); ?>
</a>
</li>
<?php endwhile; ?>
</ul>
Everything works fine, i can add projects. However My problem starts when i hit 10 projects. After 10, it doesn't display anymore. I am using jpages (jquery plugin) and filtrify to add filters to filer out the categories. They work fine, i can filter by category and i see the correct images. Even with the plugin scripts removed, i still only see a max of 10 posts. Adding more than 10 simply pushes the earlier images off and it displays the 10 latest.
So how can i stop it from being just 10.. My jpage script sets the pagination to 12 per page, but this doesn't even get a chance to kick in. I am thinking it's a post problem as I'm certain it's not the scripts.
I think I've traced an issue - I tested this: 'posts_per_page' => '20' - Which DOES display my missing posts, however i don't want to set a number as i might need lots. How can i define an unlimited number. Providing this is the issue..
If any other code is needed, please let me know, but i think this is the main part of what's controlling my posts appearing on the page.
You're on the right track.Set the value to -1 to get your desired results.
Link to the documentation: http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters
posts_per_page (int) - number of post to show per page (available with Version 2.1, replaced showposts parameter). Use 'posts_per_page'=>-1 to show all posts. Set the 'paged' parameter if pagination is off after using this parameter.

Categories