I'm having a hard time linking a menu built with custom fields to a page built the same way. I'm sure the problem is making it link via permalink, but for the life of me, I can't figure out what I'm missing.
<?php $loop = new WP_Query( array( 'post_type' => 'Employees', 'posts_per_page' => 100 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div>
<?php the_title(); ?><br />
<?php the_field('title'); ?>
Basically what I'm trying to do is on http://www.consociate.com/about/meet-the-team/, I want the links on the right to go to a template filled with custom fields (their bio information). Is this possible?
Thanks so much! I love this community!
What you are looking for can be achived by respecting the wordpress template hierarchy rules, you shouldn't hardcode links or hardcode add parameters to the links, simply use <?php get_template_part( $slug, $name ); ?> then create the resonse php file that will display the info as you want.
Related
I'm making a site for a cookery school, and I need help with writing a loop. The loop will display the types of classes they provide, as long as each of those types of classes has upcoming events. Any help would be really appreciated, as everything I've tried so far has failed.
I'm using the Advanced Custom Fields plugin as well as the Events Calendar Pro plugin from Modern Tribe. I'll refer to the post type created by the Events Calendar Pro plugin as 'events' from now on.
I have a custom post type called 'class-type' which I've set up in my functions.php file. Each post of this type is a type of class that the cookery school offers, for instance DIY Pizza Club, Street Food Mastercless etc. The single post view will have images and details of that class, with a loop of upcoming events of that category, with the categories being the class name.
The 'class-type' post type has an ACF field called 'class_age', which is a select menu with the options 'For Adults' or 'For Kids & Teens'. It also has an ACF field called 'class_to_display', which is a taxonomy field showing categories from the Tribe Events posts.
The cookery school has two locations, and each event has it's location set to one of these.
The loop I need help with will have 4 variations on four different pages, and once I have the loop working I can make these variations myself. The variations will be:
Bristol, For Adults
Bristol, For Kids & Teens
Cardiff, For Adults
Cardiff, For Kids & Teens
So using the first variation as an example, the loop will need to do the following:
Get posts of type 'class-type'.
For each post, check that the post's ACF field 'class_age' is 'For Adults'.
Get the value in the post's ACF field 'class_to_display' and store it in a variable.
Check for posts of type 'events' with that variable as their category and with 'Bristol' as their location.
If events exist that meet those criteria, display the 'class-type' post's ACF fields of 'class_main_image', 'class_title', and 'class_short_description'.
I hope that's clear, and feel free to ask if you have any questions. Again, I really appreciate anyone taking the time to help!
Here's what I have so far which goes up to step 3 above, and is tested and working (the echo in p tags is just to check it works):
<?php
$args = array(
'post_type' => 'class-type',
'meta_key' => 'class_age',
'meta_value' => 'For Adults'
);
$the_query = new WP_Query( $args );
if( $the_query->have_posts() ):
while ( $the_query->have_posts() ) : $the_query->the_post();
$cookery_class = get_field('class_to_display'); ?>
<p><?php echo $cookery_class->name; ?></p>
<?php endwhile;
endif;
wp_reset_query(); ?>
Much to my surprise, I nailed it! Here's the code that works, hope it helps somebody.
<?php
$args = array(
'post_type' => 'class-type',
'meta_key' => 'class_age',
'meta_value' => 'For Adults'
);
$the_query = new WP_Query( $args );
if( $the_query->have_posts() ):
while ( $the_query->have_posts() ) : $the_query->the_post();
$cookery_class = get_field('class_to_display');
$cookery_class = (str_replace(' ', '-', strtolower($cookery_class->name)));
$check_has_events = tribe_get_events( array(
'tribe_events_cat' => $cookery_class,
'venue' => 59
)
);
if($check_has_events) {
$image = get_field('class_main_image'); ?>
<div class="cookery-class">
<?php if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
<h3><?php the_title(); ?></h3>
<p><?php the_field('class_short_description'); ?></p>
</div>
<?php }
endwhile;
endif;
wp_reset_query(); ?>
The problem: I have a site (under development) where I have generated a custom post type called "Products" . Inside I have different categories and posts. I would like to generate a menu like behaviour to my sidebar, but using google I haven't really stumbled onto something good. Who knows, maybe my idea is all wrong and is doable using some other solution.
Currently I have used WP Query to echo out all posts under one category. So this means that I have to manually copy code to echo new category with its posts when it is created. One solution is to create a menu manually, but i'd like to keep it auto-generated because users are not keen to do extra work and ofter forgot how it is done.
So, the question: Is my solution all wrong? How can i achieve menu like behaviour with class active for clicked category and its sub item? Is it better to just use pages?
Example of my code:
<?php
$args = array(
'post_type' => 'products',
'posts_per_page' => -1,
'cat' => 1
);
$query = new WP_Query( $args );
if ($query->have_posts()) {
echo '<ul>';
while ( $query->have_posts() ) : $query->the_post(); ?>
<li>Category name, title</li>
<li class="cpt-menu-item" id="post-<?php the_ID(); ?>">
<?php the_title(); ?>
</li>
<?php endwhile;
echo '</ul>';
}
wp_reset_postdata();
?>
I just started using advanced custom fields and it is awesome. I have been struggling with this one issues and I would love some help with it.
I have setup a product name, price and image field under the products field group. I have it working so it shows the information on the product page but I have no clue how to do the loop for the overview of all products (i.e. I want to make a page that has all the products on it).
<?php if(get_field('products')): ?>
<?php the_sub_field('product-name');?>
<?php the_sub_field('product-price');?>
<?php the_sub_field('product-image');?>
<?php endif; ?>
Is anyone on the interweb able to help me out and give me a quick lesson on advanced custom fields looping? I would appreciate it very much.
I'm assuming this is a field for a custom post type?
If so, you just need to do a WordPress loop.
<?php
// Loop through custom post type
$loop = new WP_Query( array( 'post_type' => 'YOURPOSTTYPE', 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order' => 'ASC' ) );
while ( $loop->have_posts() ) : $loop->the_post();
if(get_field('products')) :
the_sub_field('product-name');
the_sub_field('product-price');
the_sub_field('product-image');
endif;
endwhile;
?>
Can I use:
<?php
if (function_exists( 'wpp_get_mostpopular' )) {
wpp_get_mostpopular('range=weekly&order_by=views&limit=8');
}
?>
Inside custom template (inside query posts) to make query with own template output:
<?php query_posts(????????); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="myclass">
<?php echo get_the_post_thumbnail( $post_id, 'thumbnail'); ?>
</div>
Please help me with this, so I don't have to edit plugin and plugin's css while I have my ready just to query posts by this plugin.
Thanks.
Plugin: http://wordpress.org/plugins/wordpress-popular-posts/
#alen imeko as far as i have understoody your requirment, why you need this plugin, you just need to show the most popular post where ever you need to, You just need to set the post to sticky and call the sticky post using the same query post method then it will automatically render your specified post at the respective place.
For this just go to post to make it sticky, at the top above the publish/update button you will see an option visibility click the edit part of it and you will the options will slide down check the checkbox having text Stick this post to the front page and after that you just need to perform query.
$args = array(
'post__in' => get_option('sticky_posts'),
'posts_per_page' => 20,
'orderby' => 'title',
'post_date' => 'DESC',
'cat' => your category id
);
query_post($args);
?>
Then you need to simply use the while loop for that the same way you do in wordpress.
On my homepage I am bringing in some custom post types using this:
<?php $loop = new WP_Query( array( 'post_type' => 'news', 'posts_per_page' => 4 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
etc....
This works fine. But then I just want to bring in a list of blog posts with the default taxonomy. So I try this:
<?php query_posts( 'cat=uncategorized' );?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
And it spits out all the custom post types, but not the one blog post I have (the hello world blog post). I feel like I have done this before without any problems, but can't figure out what I am doing wrong.
I think cat it's used with category id, in that case would be query_posts('cat=1');
If you want to use the name try ('category_name=whatever');
Hope its useful
GL
Do you have wp_reset_query some place after your first query and before the spot where you're trying to include that list?