Skip to content

Instantly share code, notes, and snippets.

@masumskaib396
Created October 23, 2019 12:18
Show Gist options
  • Save masumskaib396/1eab7aad3511adb09fd0f7338435412d to your computer and use it in GitHub Desktop.
Save masumskaib396/1eab7aad3511adb09fd0f7338435412d to your computer and use it in GitHub Desktop.
==========
custom url
<?php
$format = get_post_format();
$category = get_the_category();
$cats = array();
foreach( $category as $cat ) {
$cats[] = $cat->term_id;
}
$cats = (array) $cats;
$cats = implode(',', $cats);
$author = get_the_author_meta('ID');
$url = home_url('/') . 'blog/'; //same name page slaug
$url .= '?key=search';
$url .= '&format='.$format;
$url .= '&cat='.$cats;
$url .= '&auth='.$author;
echo '<br /> <a href="'.esc_url($url).'" target="_blank">click to view the link</a>';
?>
===================
custom-temaplte
<?php
global $wp_query;
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => $wp_query->max_num_pages,
);
if( isset($_GET) && isset( $_GET['key'] ) && !empty( $_GET['key'] ) && $_GET['key'] === 'search' ) {
$author = (isset($_GET['auth']) && !empty($_GET['auth'])) ? $_GET['auth'] : '';
$format = (isset($_GET['format']) && !empty($_GET['format'])) ? 'post-format-'. $_GET['format'] : '';
$cat = (isset($_GET['cat']) && !empty($_GET['cat'])) ? $_GET['cat'] : '';
if( !empty($author) )
$args['auth'] = (int)$author;
if( !empty($author) )
$args['cat'] = $cat;
if( !empty($format) ) {
$args['tax_query'] = array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => $format
)
);
}
}
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li><a href="'.esc_url( get_the_permalink() ).'">' . get_the_title() . '</a></li>';
?>
<h2><?php the_author() ?></h2>
<?php
}
echo '</ul>';
} else {
echo 'no posts found';
}
/* Restore original Post Data */
wp_reset_postdata();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment