Target custom field type plugin value using WP_Query - wordpress

In wordpress, using the CTU plugin, I made a custom post type called apartments with a field called available. I only want to target any post with available=yes. How would I do this? I tried the_post('available=yes')
<?php
$args = array(
'post_type' => 'apartment'
);
$the_query = new WP_Query( $args );
?>
<?php if( have_posts()): ?>
<?php while ($the_query->have_posts()): ?>
<?php $the_query->the_post(); ?>
<?php $the_field('available'); ?>
<?php endwhile; ?>
<?php else: ?>
<?php endif; ?>

i think the simplest solution is:
1. In your custom taxonomy create a term called available
2. add this to your custom query
$args = array(
'post_type' => 'apartment',
'category_name' => 'available'
);

Related

exclude custom post type from main loop wordpress

I am using wordpress and have set up a couple of Custom Post Types. I need to know how to exclude these from the main look so the Custom Post Types do not show up in the blog.
Just replace 'post_type' => 'home-post' with 'post_type' => 'post' or delete that line and it will only pull your regular posts
this code use for fetch post type data
<?php
$args = array('post_type' => 'post','posts_per_page' => -1);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<?php the_content(); ?>
</div>
<?php endwhile;?>

How to show Previous and Next link in WordPress

Below is my example code that is dynamically get the posts.
<?php
global $post;
$args = array( 'numberposts' => 4 );
$the_posts = get_posts( $args );
foreach( $the_posts as $post ){ ?>
//The Post Content Goes here...
?>
The code above will works correctly but my question is, since this is not a default blog page or a category, how can I use the posts_nav_link() so that I can still access the rest of the pages? I tried to used it but it doesn't work unless if the current page is a category. Hope you guys can help me this.
If you giving you paging in your custom post type. then i think you can do very simple you have to use wordpress plugin like wp-pagenavi after then add your custom post type in this plugin in admin panel after then add
<div class="pagination">
<?php wp_pagenavi(); ?>
</div>
<?php
global $post;
$args = array( 'numberposts' => 4 );
$the_posts = get_posts( $args );
foreach( $the_posts as $post ){ ?>
//The Post Content Goes here...
?>
<div class="pagination">
<?php wp_pagenavi(); ?>
</div>
Without plugin you can use like this
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$loop = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 3, 'cat' => '-10, -72&paged=' . $paged) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<li>
<?php the_post_thumbnail(); ?> <?php the_title(); ?>
<span><?php the_time('d.m.y') ?></span>
</li>
<?php endwhile; ?>
</ul>
</div>
<?php posts_nav_link(' — ', __('« Previous Page'), __('Next Page »')); ?>

WordPress page.php not show posts

If I add to sidebar this code I can't display anything in page.php I try reset query but no result.
<?php
$args = array(
'post_type' => 'post',
'kalba' => 'lt',
'posts_per_page' => 7
);
$new_query = new WP_Query();
$new_query->query($args);
?>
<?php if ($new_query->have_posts()) : ?>
<?php while ($new_query->have_posts()) : the_post(); ?>
<?php $new_query->the_post();?>
<?php the_title(); ?>
<div class="sidebar-line"></div>
<?php endwhile; ?>
<?php endif; ?>
got confuse y you are using
'kalba' => 'lt',
in your argument. wp_query have no any such argument 'kalba'
may be you can try and change your argument lik
$args = array(
'post_type' => 'post',
'posts_per_page' => 7
);
like this
.. hope it works fine
Before loop I add <?php rewind_posts(); ?> and when it work.

display the custom post type post in page

I have a custom post type named "audio". To display all the posts in a page I wrote the code below, but it does not work.
<?php
$post_type = "audioes";//post type names
echo "djnbfj";
$post_type->the_post();
// The Query
$the_query = new WP_Query( array(
'post_type' => $post_type,
'orderby' => 'post_date',
'order' => 'DESC',
'showposts' => 1,
));
// The Loop
?>
<?php
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="issue-content">
<?php get_template_part('includes/breadcrumbs', 'page'); ?>
<?php if ( has_post_thumbnail() ) { the_post_thumbnail();}
get_template_part('loop-audio', 'page');
?>
</div><!--issue-content-->
<?php endwhile; ?>
</div> <!-- end #left_area -->
How can i got the posts type i want the custom one written above.
Is the post type called "audio" or "audioes"? Your $post_type variable is set to "audioes".
I'm not sure what the get_template_part lines or the echo line is doing, but the below code should display your post type. You also have the post type name as "audioes" in your code, but you state that the name is "audio". Try the code below, but if the post type is named "audioes" then you'll need to change that in my code below. You can wrap additional divs, spans, or other HTML tags around <?php the_post_thumbnail(); ?> and <?php the_content(); ?> to give them CSS styles is you wish to.
<?php query_posts(array('post_type' => 'audio', 'posts_per_page' => 1, 'orderby' => 'post_date', 'order' => 'DESC')); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="issue-content">
<?php the_post_thumbnail(); ?>
<?php the_content(); ?>
</div>
<?php endwhile; wp_reset_query(); ?>

WordPress 3.0 getting list of custom pages

Is there a way to get a list of all the pages of a certain custom page type I've defined into a as you would with wp_list_pages?
Thanks a bunch,
-scott
How about using a variation of wp_query to generate a list?
<?php $mylist = new WP_Query( array( 'post_type' => 'mycustompagetype', 'posts_per_page' => 99 ) ); ?>
<?php while ( $mylist ->have_posts() ) : $mylist ->the_post(); ?>
<?php the_title( '<li>', '</li>' ); ?>
<?php endwhile; ?>
Think this would do?

Resources