Skip to content

Instantly share code, notes, and snippets.

View crondeau's full-sized avatar

Christine Rondeau crondeau

View GitHub Profile
@crondeau
crondeau / apply filters example
Created December 29, 2016 00:22
When using ACF, it's handy to a single textfield and then get WP to apply the_content filter.
<?php echo apply_filters('the_content', get_field('name_of_your_acf') ) ; ?>
@crondeau
crondeau / taxonomy-terms
Created September 17, 2015 17:36
Pull the terms and display them as a list of links.
<ul>
<?php
$terms = get_terms( 'taxonomy-name' );
foreach($terms as $term){
$term_link = get_term_link( $term );
echo '<li><a href="' . $term_link. '">' . $term->name . '</a></li>';
}
?>
</ul>
@crondeau
crondeau / gist:014d5587e416dc1001dc
Last active August 23, 2018 19:39
get_the_archive_title() filter
/*
* Remove Prefixes from archive title
*/
add_filter( 'get_the_archive_title', function ( $title ) {
if( is_category() ) {
$title = single_cat_title( '', false );
}
elseif ( is_tag() ) {
@crondeau
crondeau / WordPress tabbed Content
Last active August 29, 2015 14:16
This code snippet pulls posts from three different categories and sets them up as tabs.
<div id="tabbed-content">
<?php
/* Set up tabs at the top using your three categories.
* I've created three posts in News, Photos and Videos categories
* Both news and photos have featured images.
* The videos have a custom field (video) with the youtube embed code.
*
*/
?>
@crondeau
crondeau / get-post-multiple-tax
Last active August 29, 2015 14:06
ge post from multiple taxonomy
<?php
$args = array(
'post_type' => 'your_post_type',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'taxonomy1_label'
'field' => 'term_id',
'terms' => int // this should be an interger - term_ID
@crondeau
crondeau / ACF-img-size
Last active March 6, 2020 21:03
Display different image size using ACF
//To display an image using ACF, one would set the image custom field to image url and call the img as follows:
<?php if( get_field( 'field_name' ) ): ?>
<?php while( has_sub_field( 'field_name' ) ): ?>
<img src="<?php the_sub_field( 'image' ); ?>" alt="">
<?php endwhile; ?>
@crondeau
crondeau / gist:4ff8d4ede5306a7e8190
Last active August 29, 2015 14:01
Display list of CPT per taxonomy
<?php
$terms = get_terms('category'); //use category or your taxonomy
$count = count($terms);
//check if there are any terms
if ( $count > 0 ){
//loop through each term and query posts.
foreach($terms as $term){
@crondeau
crondeau / Display posts from taxonomy term
Last active January 4, 2016 16:39
This snippet pulls posts from a CPT from a specific taxonomy terms
/* This snippet is useful for displaying content in a sidebar for example. If you have
* a CPT and a taxonomy, you may want to display all the posts from a specific taxonomy.
* The example below pulls posts from a shop CPT, set to "Eat Drink" taxonomy term.
*/
<aside class="widget">
<h3>Eat &amp; Drink</h3>
<ul>
<?php
$loop = new WP_Query(array(
@crondeau
crondeau / VCard upload
Created April 21, 2014 22:53
Allow VCard upload via filter
add_filter('upload_mimes', 'blm_custom_upload_mimes');
function blm_custom_upload_mimes ( $existing_mimes=array() ) {
// add your extension to the array
$existing_mimes['vcf'] = 'text/x-vcard';
return $existing_mimes;
}
@crondeau
crondeau / Single Category Display
Created April 21, 2014 18:14
Pull the list of categories associated with a post and display the first one only.
<?php
/* Useful code snippet if you want to display the category title on top
* of a featured image on a list of post.
* If a post is in more than one category, this snippet
* selects the first one. If no cateogry is set, the default category appears.
*/
$post_categories = wp_get_post_categories( $post->ID );
// get first category id
$first_cat = get_category($post_categories[0]);