I have add custom post type field name 'Movies'. Now I have done these things and its working great, but the problem is, (i.e When I'm click on any movie, its showing me only one movie post, (i.e I'm click on avatar movie its showing me avatar movie post, but when I'm click on stargate movie its showing me avatar movie post. Please help its a big issue) anyone who can help me to make this code exactly which I want.
in my functions.php I have add this code:
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'Movies',
array(
'labels' => array(
'name' => __( 'movie' ),
'singular_name' => __( 'movie' )
),
'public' => true,
'has_archive' => true,
)
);
}
Then in my template file add this where I want to show post:
<?php
$args = array( 'post_type' => 'movies', 'posts_per_page' => 1 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1>
<a title="<?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?>
</a>
</h1>
<div class="entry-content">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; ?>
I'm new for this thing, so please explain me as much as you can, where I paste it or what I do?
I can't see how you structured your links to those movie-posts, but you should give them a variable, so the page where the movie-post shows up knows what to show!
e.g $moviename
and in your template you modify the $args array to:
$args = array( 'post_type' => 'movies', 'posts_per_page' => 1, 'name' => $_GET['movie'] );
Should work, at least that explains why it always displays the same movie-post:
Your query hast no information what movie to display, at the moment it just takes the movie-posts table and displays the first one - because of the posts_per_page limit to 1.
Hope that makes sense...
Related
I'm facing an issue with my website.
I would like to display all my custom post type named "Projets", and for each item, I want to get several term names to put in my data element.
Displaying all my post is not an issue, it's working well. I manage to display one term name using "get_terms()", but I don't know how to display several terms and put them in the right place.
I have 3 different custom taxonomy : city, typo and statut.
There is my code :
<?php
$args = array(
'post_type' => 'projets',
'posts_per_page'=>'99',
'order' => 'ASC',
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<li class="content_item active" data-city="CITY_NAME_HERE" data-typo="TYPO_NAME_HERE" data-statut="STATUT_NAME_HERE">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('custom-size', ['class' => 'content_item_img', 'title' => 'Image du projet']); ?>
<h4><?php the_title(); ?></h4>
</a>
</li>
<?php endwhile;
wp_reset_postdata();
?>
Thanks for the help!
Try this:
Inside the loop, you get the taxonomy like this (eq. "city"):
$cities = get_terms( array(
'taxonomy' => 'city',
'hide_empty' => false,
) );
You get an array of all the terms of the Taxo.
Where you need them, you have to loop them, here to give you an idea.
if(!empty($cities)){
foreach($cities as $city){
echo $city->name.', ';
}
}else{
echo 'No Cities.';
}
Comma Separated custom categories inside the loop.
<?php echo get_the_term_list( $post->ID, 'cutom_category', '', ', ', '' ) ?>
As you know, the following code publishes the latest content in a group in its WordPress
<?php
$my_query = new WP_Query('showposts=1&cat=172');
while ($my_query->have_posts()):
$my_query->the_post();
$do_not_duplicate = $post->ID;
?>
I want to make changes to this codeŘ So that the last article in a group is not displayed and
, And the pre-final content of the same group will be displayed.
thank u
I think you might want to take a look at the offset and order parameters.
I'm guessing that the snapshot in your question is what you call a "group"...
Depending on what you call the last article (last published or first published) you might want to change the order from 'DESC' to 'ASC'.
<?php $query = new wp_query( array( 'post_type' => 'post', 'cat' => '172', 'post_status' => 'publish', 'posts_per_page' => '3', 'offset' => '1', 'order' => 'DESC' ) ); ?>
<?php if ( $query->have_posts() ): while ( $query->have_posts() ): $query->the_post(); ?>
<a aria-label="<?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php endwhile; endif; ?>
gl.
EDIT: Just an idea... You could also simply go with pure CSS and targeting your last post with :last-child ... see https://developer.mozilla.org/fr/docs/Web/CSS/:last-child
I found an issue after importing the items. New items cant't be displayed on the list in frontend but they are added to the admin dashboard. Manually updated I can see them on the list.
CMS: Wordpress
Plugins I use: Essential Real Estate, WP All Import.
What I did: I heard about post meta updating and I also saw that it can be a query problem (but the items added manually are displayed and I can't see any problem with it).
The question: how can I see them added right after importing ?
Thank you
The problem is in this part of code but I can't see the reason for not displaying items. I import the items and the only old posts creating manually are shown.
$args = array(
'posts_per_page' => $custom_property_items_amount,
'post_type' => 'property',
'orderby' => array(
'menu_order'=>'ASC',
'date' =>'DESC',
),
'offset' => ( max( 1, get_query_var( 'paged' ) ) - 1 ) * $custom_property_items_amount,
'ignore_sticky_posts' => 1,
'post_status' => array('publish','pending','draft','future','private'),
);
$data = new WP_Query( $args );
<div class="<?php echo join( ' ', $wrapper_classes ) ?>">
<?php if ( $data->have_posts() ) :
while ( $data->have_posts() ): $data->the_post(); ?>
<?php ere_get_template( 'content-property.php', array(
'custom_property_image_size' => $custom_property_image_size,
'property_item_class' => $property_item_class
)); ?>
<?php endwhile;
else: ?>
<div class="item-not-found"><?php esc_html_e( 'Not found', 'essential-real-estate' ); ?></div>
<?php endif; ?>
<div class="clearfix"></div>
<?php
$max_num_pages = $data->max_num_pages;
ere_get_template( 'global/pagination.php', array( 'max_num_pages' => $max_num_pages ) );
wp_reset_postdata(); ?>
</div>
I've figured a way to enable adding categories to a PAGE (not a post). And I was just wondering if there was a way to display PAGES in a post loop, this is my code:
<?php query_posts('cat=540'); ?>
<div class="blog_module">
<?php if(has_post_thumbnail()) {
the_post_thumbnail(array(150,150));
} else {
echo '<img class="alignleft" src="'.get_bloginfo("template_url").'/images/empty_150_150_thumb.gif" width="150" height="150" />';
}
?>
<div class="entry">
<h3 class="blog_header"><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<a class="button_link" href="<?php the_permalink(); ?>"><span>Read More</span></a>
</div>
</div>
However, this displays:
Which isn't what I want, it ONLY DISPLAYS POSTS and not the pages I have assigned to Category ID 540.
Please could someone help with a loop that would display pages that have been assigned to a category.
Thank you in advance.
Sure its easy. I guess the following should work (untested):
query_posts(array('cat'=>540,'post_type'=>page));
You can also use WP_Query which is more flexible than query_posts:
$q = new WP_Query(array('cat'=>540,'post_type'=>page));
while($q->have_posts()): $q->the_post();
// your post here
endwhile;
This should be even more flexible:
$args = array(
'post_type' => 'page',
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => 540
),
),
);
$query = new WP_Query( $args );
If you need posts AND pages try this:
'post_type' => 'any'
All information you need you can find on these links: https://developer.wordpress.org/reference/functions/query_posts/
https://codex.wordpress.org/Class_Reference/WP_Query
looking to achieve something similar to this page where user can enter a thought into a form field and on submission this then posts straight onto the page.
http://hcma.ca/
Would using wordpress comments be best for this? Or some way of sending the form submission to populate a repeater advanced custom field on the page. Can anyone advise how best to achieve this?
Also wondering about spam. The site above has no captcha or similar (as far as I can tell). What's the deal with this?
Thanks!
If you don't want to use a paid plugin, you can create a new Custom Post Type and then display the results on the page you want. You should follow this tutorial here
In short:
Create a new post type:
// Our custom post type function
function create_posttype() {
register_post_type( 'movies',
// CPT Options
array(
'labels' => array(
'name' => __( 'Movies' ),
'singular_name' => __( 'Movie' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'movies'),
)
);
}
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );
Display the results in a page:
<?php
$args = array( 'post_type' => 'movies', 'posts_per_page' => 10 );
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<div class="entry-content">
<?php the_content(); ?>
</div>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
You can use then this free plugin to add Google reCaptcha to avoid spam