New answers tagged

2

Notes: Currently you're echo-ing the output of wp_get_archives(). In order to return it, we must set the echo input parameter to false. You're assuming the output of wp_get_archives() is an array, but it's a string. Workaround: Here's one way, by counting the <li> instances, with the html format: $args = [ 'parent' => 0, 'hide_empty' ...


4

Expanding my earlier comment into a more detailed answer: In regards to your decision not to use WP_Query, pre_get_posts is actually an excellent choice to make, rather than creating a new instance of WP_Query. In fact, pre_get_posts is exactly what you should be using when you want to change the main query. Rather than executing a separate query on each ...


2

Probably the most "WordPress-y" approach to such a problem is to store the date of your 'event' custom post-type in the post's metadata. Enabling users to set meta-data on a post is usually accomplished by using the 'register_meta_box_cb' argument to the register_post_type() function to add an extra "meta box" interface to the pages for creating or editing a ...


0

comment is related to post, page, or custom post type content, not an archive page, so I think you rather need add a front form than comment form on archive pages. You can use the "visual form builder" or some other front form plugins to get the done.


1

You can try to build some options custom page to allow users to change some text. there are many plugins for easily creating that functionality. I will suggest you the most popular - https://www.advancedcustomfields.com/add-ons/options-page/ You can use the following code with ACF PRO: /** * Create ACF setting page under Campaign CPT menu * * @since ...


1

You can use Options API or Setting API to store the data in the database. Write a plugin to create a meta box for the introduction text and show that text on the archive-unicorn.php. Or you can utilize the description parameter when you register_post_type and print it in the archive-unicorn.php like this: $unicorn_obj = get_post_type_object('unicorn'); if ...


2

In each of your hooks & filters handlers, in addition to checking for archive conditions, check for a custom query var that you can then set for a custom/manual query. For example, where you might have: function wpse_223991_pre_get_posts( $wp_query ) { if ( $wp_query->is_main_query() && $wp_query->is_post_type_archive( 'my_post_type' ) ...


0

I am unable to comment. so i am answering here.. please check the link. May this help you. Click Here for the answer


5

If I am understanding you have a taxonomy that is shared across multiple post types? And you want to make a custom template for each post type using the Wordpress's templating system. Which isn't possible. What you could do is add conditionals to your taxonomy-disrupt-categories.php to check what the current post type is and load different template parts ...


2

Make use of custom parameter, lets call it wpse__current_year, which will accept two values, true (includes current year) and false (excludes current year). Lets incorporate that function show_monthly_archive( $post_type ) { $current_year_args = array( 'type' => 'monthly', 'limit' => '12', ...


0

I think this may be what you need - customizing feeds Feed templates are in wp-includes. It's pretty straight forward from there to edit a loop to exclude a post or create a new feed template for the custom post type.


0

WP_Query offers a date_query parameter, allowing you to set a range with before and after. $args = array( 'date_query' => array( array( 'after' => 'January 1st, 2015', 'before' => 'December 31st, 2015', 'inclusive' => true, ), ), ); $query = new WP_Query( $args ); For further ...


0

Try those args: 'date_query' => array( //start date array( 'year' => $startyear, 'month' => $startmonth, 'compare' => '>=' ), //end date array( 'year' => $endyear, 'month' => $endmonth, 'compare' => '<=' ) ),


0

Add this in your $args 'date_query' => array( array( 'after' => 'January 1st, 2015', 'before' => array( 'year' => 2016, 'month' => 1, 'day' => 1, ), 'inclusive' => true, ), ),


0

It should work but note that the date structure contains the structure for year, month and day archives as well, so you'll need something like: add_action( 'init', function() { global $wp_rewrite; $wp_rewrite->date_structure = 'archives/%year%/%monthnum%/%day%'; }); Don't forget to visit your permalinks settings page in wp-admin so that rewrite ...



Top 50 recent answers are included