How To Call WP_Query From A Subdomain?

Why don’t you try using the WP API? You could then pull posts from a URL like this … http://subdomain.example.com/wp-json/posts You can also set custom post types to use the WP API and then access them also in a similar manner, you would need to add the following to your CPT args: $args = array( … Read more

Fetching $_POST from Page Template into functions.php

Assign the value of you $_POST variable to a html element or javascript variable in front-page.php like //html element <input type=”hidden” value=”<?= $_POST[‘variable’]?>” id=”post-variable”> or in javascript variable var postVariable = “<?= $_POST[‘variable’]?>”; Now in ajax call, you can get the value as var myValue = jQuery(‘#post-variable’).val(); //if you set value to html element or … Read more

Pagination in WP_Query?

Put the following code in functions.php # +++++++++++++++++++++++++++++++Pagination ++++++++++++++++++++++++++++++++++++++ function kriesi_pagination($pages=””, $range = 2) { $prev = __(‘« Prev’); $next = __(‘Next »’); $showitems = ($range * 2)+1; global $paged; if(empty($paged)) $paged = 1; if($pages == ”) { global $wp_query; $pages = $wp_query->max_num_pages; if(!$pages) { $pages = 1; } } if(1 != $pages) { echo … Read more

Show more than one post on the main page excluding certain category

If you are altering main query then use pre_get_posts filter instead of WP_Query. add_action(‘pre_get_posts’,’wpse224610_alter_query’); function wpse224610_alter_query($query){ $cat_id = get_cat_ID(‘Featured articles’); $exclude_cat_id = -$cat_id; if( !is_admin() && $query->is_main_query() ){ $query->set( ‘cat’, $exclude_cat_id ); $query->set( ‘posts_per_page’, 4 ); } } And the main loop will be if( have_posts() ): while( have_posts() ): the_post(); //The loop endwhile; endif; … Read more

Rewrite rule pagination on different url levels

I have added extra rewrite rules for pages with no item_width and item_height in combination with pagination as follows: /** * Adds rewrite rules for shop category */ function gtp_add_shop_rewrite_rules() { // shop-category/category/item_width/item_height/page/2/ add_rewrite_rule( ‘^shop-category\/([^/]*)\/([^/]*)\/([^/]*)\/page\/([0-9]*)$’, ‘index.php?shop-category=$matches[1]&item_width=$matches[2]&item_height=$matches[3]&paged=$matches[4]’, ‘top’ ); // shop-category/category/page/2/ add_rewrite_rule( ‘^shop-category\/([^/]*)\/page\/([0-9]*)$’, ‘index.php?shop-category=$matches[1]&paged=$matches[2]’, ‘top’ ); // /shop-category/category/item_width/item_height/ add_rewrite_rule( ‘^shop-category\/([^/]*)\/([^/]*)\/([^/]*)$’, ‘index.php?shop-category=$matches[1]&item_width=$matches[2]&item_height=$matches[3]’, ‘top’ ); // /shop-category/category/item_width/ add_rewrite_rule( … Read more