New answers tagged

2

You may want to look at the TwentySixteen theme, which does it this way: In single.php: get_template_part( 'template-parts/content', 'single' ); Several templates are grouped in the 'template-parts' folder. You could use a similar logic for your custom post type. It seems that the technique comes from _underscores.


0

The first thing I would recommend is verify the number of posts your query is returning using the following: $apartquery->found_posts


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 ...


-1

Just replace your short code function with given code. Then call it as usual. It should work perfectly now. //registering the shortcode to show testimonials function load_testimonials($a){ $atts = shortcode_atts( array( 'rand' => '', 'max' => '', 'id' => '', ), $a); $args = array( "post_type" => ...


0

Without adding your custom post type, it looks like you've got the function called wrong on the second one add_action('admin_menu', 'mytheme_add_box'); // Add meta box function referans_add_box() { Do you want to say add_action('admin_menu', 'referans_add_box'); // Add meta box function referans_add_box() {


0

Hopefully this is what you were asking for? Make sure you update your permalinks (just click update) afterwards. This will do yourwebsite.com/vege/%vege-category%/%post% In your example, you didn't register the taxonomy type, and additionally you need to add the function to put the category slug into the permalink. function my_custom_post_vege() { ...


0

If you are simply trying to echo the excerpt in a specific part of a theme, you can simply use the following code within the loop: <?php $excerpt = get_the_excerpt(); echo substr( $excerpt, 0, 15 ) . '&hellip;'; ?> If you want to filter the excerpt globally (in archives, blog pages, etcetera) to match any post part of one or more ...


0

Put the following code in your functions.php function excerpt($limit) { $excerpt = explode(' ', get_the_excerpt(), $limit); if (count($excerpt)>=$limit) { array_pop($excerpt); $excerpt = implode(" ",$excerpt).'...'; } else { $excerpt = implode(" ",$excerpt); } ...


0

You could try GIF technology. This way, you won't need to unnecessarily write custom code. The post title is not the best place for multiple images when you could conveniently use a slider in the page's body.


2

the first request don't show any custom post type (polylang_mo is a custom post type) polylang_mo is a private custom post type so unless I explicitly request this post type, it won't be included. the second request shows only 1 page (instead of 3) Polylang was actually filtering the results. Adding --skip-plugins=polylang makes the 3 posts ...


1

It's nothing to do with the class itself - you are using the reserved input name post, which is conflicting with WordPress core: <input type="checkbox" name="post[]" value="%s" /> Change it something unique to your theme/plugin e.g. name="my_plugin_ids[]"


0

SOLVED I found the answer in another post that was answered by @Gustav for anyone looking a solution like you can follow the link or view the code below it works perfectly. http://wordpress.stackexchange.com/questions/123059/list-post-from-current-taxonomy-children THE WORKING CODE <?php $term_slug = get_query_var( 'term' ); ...


0

Welcome to Stack exchange :) Some other plugin ( or your plugin elsewhere ) may be getting executed later, and maybe adding some elements to the array. Try to give your hook a higher priority, replacing your tweak method with following... function tweak() { foreach( $this->get_post_types('objects') as $type => $data) { ...


-1

It seems like there are lots of different problems and potential solutions here, but after trying every other suggested solution, none of which worked, I found something that worked. Add: flush_rewrite_rules(); after you call register_post_type.


0

If your search results page is defaulting to the index.php it's because you don't have a search.php template in your theme. Quite likely, your index.php template is also handling search results when items are found, too. search.php template, if it exists should be used for search results whether or not any items were found. Just create one and put what you ...


1

Use 'supports' => [ 'title', 'editor', 'thumbnail' ] – different values, not keys. If we look into register_post_type(), we find these lines: if ( ! empty( $args->supports ) ) { add_post_type_support( $post_type, $args->supports ); unset( $args->supports ); } elseif ( false !== $args->supports ) { // Add default features ...


0

You need to hook in to the Posts list table using the manage_posts_extra_tablenav filter, but you can show the filter yourself by using the wp_dropdown_categories() function. The only two $args that you are really interested in are depth and taxonomy, but I've included all of the defaults below. Full details of the wp_dropdown_categories() function can be ...


0

single.php file or custom single-{post_type}.php <?php while ( have_posts() ) : the_post(); get_template_part( 'content', get_post_format() ); endwhile; make a new template file content-video.php customize video format post. When you add post format to custom post type add support in your function.php add_post_type_support( 'post_type_name', ...


0

Just use the single-{post-type}.php template, as described in the Template Hierarchy.


3

Did you try just using option.php? <form method="post" action="options.php">


0

Custom template should be archive-gallery.php instead of archive-posttype.php It's archive-$posttype.php where $posttype is the custom post type slug. WordPress first looks for archive-$posttype.php and if it's not available then chooses archive.php Update Same for the custom taxonomies also , the flow is: taxonomy-$taxonomy-$term.php --> ...


0

Assuming post type is my-post-type. We can create a page template with custom query using WP_Query. Let's say we create template-multier.php with the below code in the root directory of the active theme. <?php /* Template Name: Custom Post Type Archive */ //Custom header stuff here //Custom query for `my-post-type` $args = ...


0

@darrinb I have solved the problem. Your code helped me a lot although had a error. :) The error was getting the 'terms': $terms = get_terms( array( 'taxonomy' => $taxonomy->name, 'hide_empty' => true, ) ); Following the codex: The correct way is the following: $arg = array( 'hide_empty' => true, ...


-1

I found the issue was with the other event plugin I had, for some reason, it made the events page an archive as well and wasn't listing anything. Thank you all for your input. -AJ


1

Custom Post Type registrations in WordPress are not persistent. CPT only exists as long as registration code had been executed in a current page load. If the registration is disabled the data will be in database, but pretty much ignored and invisible to WP core. It is hard to guess what happened in your specific case. Most likely plugin had introduced ...


0

function your_function() { global $current_user; if($current_user->roles[0] == 'administrator') { add_meta_box(your parameters); // fill in your parameters } } add_action('admin_init','your_function');


1

Well it turns out Apple News doesn't accept password-protected RSS feeds. Thanks for the help!


0

Your rule doesn't work for custom post types because pagename is the query var specific to the page post type. Your CPT query vars are the slugs you registered them with, doujinshi_en and doujinshi_jp. You might be able to fix it by adding in additional post types via pre_get_posts: function wpd_add_custom_types( $query ){ if( ...


0

Try this function search_pre_get_posts( $query ) { if ( $query->is_search() && $query->is_main_query() ) { $currentdate = date('Y-m-d'); $enddate = strtotime(date('Y-m-d') . "+7 days"); $enddate = date('Y-m-d',$enddate); $query->set( 'meta_query', ...


1

I would consider this not really a typical WP question – maybe you should ask over at http://unix.stackexchange.com – but maybe this could already help anyways: If you have access to the server config and you know the IP address of FB Instant Articles and Apple News you could for example block everybody from accessing your feed – but allow FB Instant ...


1

It works with Advanced Custom Fields (Pro). You can create dynamic repeat boxes with this plugin


0

Whatever you have in content-feature.php is going to be repeated for each article/post/feature. If you want all of them to be within the same <ul> you'll need to put everything else outside into the front-page.php main template. So: front-page.php if ( $loop -> have_posts() ) : ?> <ul> <?php /* Start the Loop */ ...


0

If anyone's interested, the solution was quite close, I only had to specify the rewrite rule with &post_type=film : add_rewrite_rule( 'projections_dvd/([^/]+)/?$', 'index.php?name=$matches[1]&post_type=film&is_projections_dvd=1', 'top' ); I also changed the query vars to make it simpler : function wpd_query_var( $query_vars ) { ...


1

Try this: <?php $object = 'post'; $output = 'objects'; $taxonomies = get_object_taxonomies( $object, $output ); $exclude = array( 'post_tag', 'post_format' ); if ( $taxonomies ) { foreach ( $taxonomies as $taxonomy ) { if( in_array( $taxonomy->name, $exclude ) ) { continue; } $terms = get_terms( array( ...


1

You'll have to do this in two steps. First, you will create a post in the draft mode, using wp_insert_post(). The wp_insert_post itself will return to you the ID of the inserted post: <?php $new_post = array( 'post_title' => 'Draft title', 'post_status' => 'draft' 'post_type' => 'my_custom_type' ); $postId = ...


1

Check the documentation: Return: (int|WP_Error) The post ID on success. The value 0 or WP_Error on failure. Thus: $result = wp_insert_post( $data ); if ( $result && ! is_wp_error( $result ) ) { $post_id = $result; // Do something else }


2

Inside get_posts() method of the WP_Query class (line 3769), you will find out this filter: $this->posts = apply_filters_ref_array( 'the_posts', array( $this->posts, &$this ) ); It's the very first hook you can use to modify queried posts on both back-end and front-end. $this->posts is an array of queried posts so it's easy to modify the ...


1

The problem must be how you define your post variable. You assume it's the global $post but that's not always the case especially in non-singular pages like archives. The filter itself provides the correct post instance that's it's been called on as 2nd parameter. function product_type_permalink( $post_link, $post ) { // current post is already ...


2

WordPress tries to guess what post the user want to see by post name. That is what is making both example.com/new-bikes/ktm/duke/ktm-690-duke-2012/ and example.com/new-bikes/ktm/yamaha/ktm-690-duke-2012/ return the same and "correct" content. What is important is that, if you see at the source code of example.com/new-bikes/ktm/yamaha/ktm-690-duke-2012/, you ...


0

Go to Settings/permalinks and click save. To prevent this from being a problem with plugins, or themes that insatiate CPT's/ Taxonomies there is the function flush_rewrite_rules. here is the link from the codex.


0

SOLVED! In response to @tomjnowell : Yep! you are right, I'm not giving enough details nor context, sorry. I'm not used to post questions here, nor the english is my mother tongue, as you can see. So thanks to be so patient as to help me. What I wanted What I intended is to make a search by several post meta AND, optionally, ALL the post meta PLUS the ...


0

Just use strip_tags <?php echo strip_tags(get_the_term_list( $post->ID, 'CUSTOM-TAXONOMY', ' ',', ')); ?>


0

Solved, I removed : 'meta_compare' => '=' !


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 ...


0

If you want the taxonomy under products post type then you must change your code from. register_taxonomy( 'manufactures', 'manufactures', array( 'hierarchical' => true, 'labels' => $labels, 'query_var' => true, 'show_admin_column' => false, 'show_ui' => true ) ); to register_taxonomy( ...


0

So, what you are trying is to add manufactures taxonomy for product post type of Woocommerce Plugin? Change manufactures object type to product and it should work. register_taxonomy( 'manufactures', 'product', array( 'hierarchical' => true, 'labels' => $labels, 'query_var' => true, 'show_admin_column' ...


0

The problem was related with a WordPress update and the permalinks, I simply updated the permalink structure (without modifying it) and everything worked fine. I don't know why, but if you're facing the same problem or something similar is worth trying.


0

Create a another filter to remove post title and post content remove search terms try this if this helpful for you add_filter( 'posts_search', 'custom_post_search_author_do', 10, 2 ); function custom_post_search_author_do($search, $query ){ if( ! empty($search) && $query->is_main_query() && !is_admin() ...



Top 50 recent answers are included