Skip to content

Instantly share code, notes, and snippets.

@alwerner
alwerner / Display Wordpress categories for Custom Post Types
Last active December 14, 2015 05:59
Display categories for Custom Post Types, add to functions.php
// Display categories for Custom Post Types, add to functions.php
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if(is_category() || is_tag()) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('post','news'); //substitute cpt - in this case 'news' - for post type
@alwerner
alwerner / Display Wordpress Custom Post Types on home page
Last active December 14, 2015 05:59
Display Wordpress Custom Post Types on home page, add to functions.php
// Display Custom Post Types on home page, add to functions.php
add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', array( 'news' ) ); //add cpt, in this case 'news' to array
return $query;
@alwerner
alwerner / Using Wordpress Tags with Custom Post Types
Last active December 14, 2015 05:59
Using Wordpress Tags with Custom Post Types, goes in functions.php
// Using Tags with Custom Post Types, goes in functions.php
function add_custom_types( $query ) {
if( is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
// this gets all post types:
// $post_types = get_post_types();
// alternately, you can add just specific post types using this line instead of the above:
$post_types = array( 'post', 'news' );
@alwerner
alwerner / retroactively add items to .gitignore
Last active March 21, 2022 23:14
retroactively add items to .gitignore
// make change to .gitignore
git rm --cached <filename>
// or, for all files
git rm -r --cached .
git add .
// then
@alwerner
alwerner / Adding a git alias to .gitconfig
Last active December 13, 2015 19:38
Adding a git alias to .gitconfig
git config --global alias.<NAME> "<COMMAND>"
git rm -r --cached .
This removes everything from the index, then just run:
git add .
Commit it:
git commit -m ".gitignore is now working"
@alwerner
alwerner / php conditional loading based on host
Last active October 12, 2015 20:29
php conditional loading based on host
<?php
if ($_SERVER["HTTP_HOST"] == 'mydomain.com' || $_SERVER["HTTP_HOST"] == 'www.mydomain.com' ) {
// insert, for instance, analytics code here.
}
@alwerner
alwerner / Git Remove Deleted Files
Last active October 10, 2015 10:27
Remove Deleted Files
# to remove already deleted files:
git add -u .
git commit -m "manually deleting files"
@alwerner
alwerner / ssh path to github repo
Last active October 9, 2015 08:08
ssh path to github repo
Make sure you're using the SSH one:
ssh://git@github.com/username/repo.git.
And NOT the https or git one.
Fix the url in the .git/config file.