This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('pre_get_posts','exclude_pages_from_search'); | |
function exclude_pages_from_search( $query ){ | |
if( $query->is_main_query() && is_search() ){ | |
$post_ids = array(123, 456, 345); // Replace with your own ids | |
$query->set('post__not_in', $post_ids); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'wp_unique_post_slug', 'numeric_post_slug', 10, 6 ); | |
function numeric_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ) { | |
global $wpdb; | |
if ( ! is_numeric( $original_slug ) || $slug === $original_slug ) { | |
return $slug; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'get_the_archive_title', function ($title) { | |
if ( is_category() ) { | |
$title = single_cat_title( '', false ); | |
} elseif ( is_tag() ) { | |
$title = single_tag_title( '', false ); | |
} elseif ( is_author() ) { | |
$title = '<span class="vcard">' . get_the_author() . '</span>' ; | |
} elseif ( is_tax() ) { //for custom post types |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function custom_post_tax_query() { | |
$args = array( | |
'post_type' => 'custom-post-type', // Replace with custom post type | |
'posts_per_page' => -1, | |
'order' => 'ASC', | |
'orderby' => 'menu_order', | |
'tax_query' => array( array( | |
'taxonomy' => 'custom_taxonomy', // Replace with custom taxonomy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function sibling_pages_query() { | |
$parentPageObject = get_page_by_title( 'Parent Page' ); // Replace with parent page title | |
$output = ''; | |
if ( $parentPageObject ) { | |
$subPagesArray = get_pages( | |
array( | |
'child_of' => $parentPageObject->ID, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function pages_query_acf() { | |
// Parameters available here: https://developer.wordpress.org/reference/classes/wp_query/ | |
$args = array( | |
'post_type' => 'page', | |
'posts_per_page' => -1, | |
'order' => 'ASC', | |
'orderby' => 'menu_order', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function taxonomy_terms_query() { | |
// Parameters available here: https://developer.wordpress.org/reference/classes/wp_term_query/__construct/#parameters | |
$args = array( | |
'taxonomy' => 'product_cat', | |
'child_of' => 5, // Get child terms of category with ID 5 | |
'parent' => 5, // Get direct-child terms of category with ID 5 | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function posts_query() { | |
// Parameters available here: https://developer.wordpress.org/reference/classes/wp_query/ | |
$args = array( | |
'post_type' => 'post' // Replace with other post type if you want | |
); | |
$posts = get_posts( $args ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_shortcode( 'current_year', 'current_year' ); | |
function current_year() { | |
return date("Y"); | |
} | |
?> |