Skip to content

Instantly share code, notes, and snippets.

View thetwopct's full-sized avatar

James Hunt thetwopct

View GitHub Profile
@thetwopct
thetwopct / install-wordpress.sh
Last active December 22, 2018 05:42
Download & Install WordPress via Curl on Mac in Terminal
# run in root directory you want WordPress installed in
curl -LO https://wordpress.org/latest.zip
unzip latest.zip
mv wordpress/* .
rmdir wordpress
rm latest.zip
@thetwopct
thetwopct / list-cpt-taxonomies.php
Created December 22, 2018 05:46
Show all custom post type taxonomies in a list with their posts (like Sitemap)
<?php
$object = 'treatments'; // CPT TYPE
$output = 'objects';
$taxonomies = get_object_taxonomies( $object, $output );
$exclude = array( 'post_tag', 'post_format' );
if ( $taxonomies ) {
foreach ( $taxonomies as $taxonomy ) {
@thetwopct
thetwopct / CPT-categories-loop.php
Last active October 20, 2023 09:21
Loop through CPT categories and display posts within
<?php
/*
* Loop through Categories and Display Posts within
https://wordimpress.com/loop-through-categories-and-display-posts-within/
*/
$post_type = 'treatments';
// Get all the taxonomies for this post type
@thetwopct
thetwopct / show-taxonomy.php
Created December 22, 2018 05:49
Show taxonomy of a post if it exists
<?php
if( false != get_the_term_list( $post->ID, 'brands' ) ) {
echo 'Brand: ' . get_the_term_list($post->ID,'brands', ' ', ' ', '' ) . "<br />";
}
?>
@thetwopct
thetwopct / custom-taxonomy.php
Created December 22, 2018 05:50
List all posts by custom taxonomy
$custom_terms = get_terms('custom_taxonomy');
foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array('post_type' => 'custom_post_type',
'tax_query' => array(
array(
'taxonomy' => 'custom_taxonomy',
'field' => 'slug',
'terms' => $custom_term->slug,
@thetwopct
thetwopct / functions.php
Created December 22, 2018 05:51
WordPress Maintenance Mode in Functions.php only
// MAINTENANCE MODE
function wp_maintenance_mode(){
if(!current_user_can('edit_themes') || !is_user_logged_in()){
wp_die('<h1 style="color:black">Site Name - We\'ll be back soon</h1><br />We are performing scheduled maintenance. Our website will be back shortly.', 'Title (Maintenance Mode)');
}
}
add_action('get_header', 'wp_maintenance_mode');
// Comment the last line to start/stop maintenance mode
@thetwopct
thetwopct / instagram-pull.php
Created December 22, 2018 05:52
PHP pull Instagram feed and display with cache
<?php
$cache_file = getcwd() . '/media/latest_gram.json';
$cache_life = '120'; //caching time, in seconds
if ( !file_exists($cache_file) or ( time() - filemtime($cache_file) >= $cache_life ) ) {
file_put_contents( $cache_file, file_get_contents('https://api.instagram.com/v1/users/self/media/recent/?access_token=xxx&count=1') );
}
$json = file_get_contents( $cache_file );
$ig_array = json_decode( $json );
?>
@thetwopct
thetwopct / display-acf.php
Created December 22, 2018 05:53
If get_field exists for displaying custom fields (ACF)
<?php if (get_field('custom-field') != NULL) : ?>
<p>This is my value: <?php the_field('custom-field'); ?></p>
<?php endif; ?>
@thetwopct
thetwopct / show-taxonomy.php
Last active December 22, 2018 05:54
Show taxonomies of a CPT post as links without comma at end
// array of CPTs (add more or less as required)
$myarray = array('custompost1','custompost2','custompost3');
$terms = get_the_terms( $post->ID , $myarray );
// init counter
$i = 1;
foreach ( $terms as $term ) {
$term_link = get_term_link( $term, $myarray );
if( is_wp_error( $term_link ) )
continue;
@thetwopct
thetwopct / contact-form-7.html
Created January 14, 2019 14:59
Contact Form 7 defaults
[text* your-name placeholder "name"]
[email* your-email placeholder "email"]
[textarea* your-message class:comment-form]
[honeypot your-website validautocomplete:true move-inline-css:true]
[submit "Send"]