Tag Info

New answers tagged

1

Your argument for is_singular() is wrong It should be an array is_singular(array('post','movie')) You can read more about the argument passed from this link here


0

You are actually not that far away with pre_get_posts, you just need to first grab the current post types that are in the query before adding your own. Also, I'd recommend using a $priority of 99 so that the action is hooked after any other pre_get_posts hooks, meaning that if users add there own CPT's (or built in post types) they are detected and included ...


0

WordPress allows to do this rather neatly for pages, supporting page-$slug.php and page-$id.php templates in hierarchy. Unfortunately it doesn't apply to posts and Custom Post Types. So your options are either handling this inside single-services.php (in one file, or by further including other template files) or adjusting hierarchy to use custom templates ...


0

For reference of other I've managed to get help with this with help from wordpress support forums. You can specify a second parameter in get_terms to exclude specific term IDs: $term_args = array( 'exclude' => array(5, 8) ); $custom_terms = get_terms('service_categories', $term_args); In the case above, we're excluding terms with ID 5 and 8. ...


0

I really should just try to think things out thoroughly before instantly asking questions. I found a very easy solution. It's not exactly adding "pages" but it does what I need. When registering the custom post type, there are two things which need to be specified. By default, the parameter hierarchical is set to false. Solution: set hierarchical => ...


0

You have missed meta_value parameter. You can use like this : $today=date('Y-m-d'); $args = array( 'numberposts' => 10, 'post_type' => 'events', 'meta_key' => 'event_date', 'meta_value >=' => $today ); // get results $the_query = new WP_Query( $args );


0

There seems to be a problem with the custom post type feed support when has_archive is false. Check for example these tickets: #16415 Don't require CPTs to have archives in order to have feeds #24867 Feeds for custom posts type can not be set independently of has_archive and supports => comments So regarding the native support, it looks like you might ...


0

This seems to solve the issue: add_filter('pre_get_posts', 'query_post_type'); function query_post_type( $query ) { if( is_category() && $query->is_main_query() && empty( $query->query_vars['suppress_filters'] ) ) { $query->set( 'post_type', array( 'post', 'nav_menu_item', 'event')); return $query; } }


0

Currently your meta query is exclusive and you need to make it inclusive. For example, you can save always the meta field show_in_news for match-report custom post type, even when the value is false. Then, you can include posts if custom show_in_news doesn't exist (standard posts) or if it exists and it is "true" for custom post type: $queryArgs = array( ...


1

The first section of this question have been answered before. Basically, there are no index pages for archives, and there never will be. For a complete explanation, feel free to check this post I have recently done on this subject. Why did wordpress think that is post_name and post type is post? You might or might not know this, but Wordpress uses ...


1

You can get the list of other posts with same post parent by running a custom query. You should supply parent post id in post_parent parameter to WP_Query and exclude current post from custom query. So this will be the custom query. $parentpost = wp_get_post_parent_id( $post->ID ); if ( $parentpost && $parentpost != '0' ) { $currentpost = ...


1

As I said, this whole setup you are after is not possible natively with pretty permalinks. Your setup probably works with default permalink structure as both queries (the main query and your custom query) read these permalinks in the same way. When you switch to pretty permalinks, the two queries on the single page interpret the URL differently causing one ...


1

You should be using a tax_query for this operation. The category parameters won't work with custom taxonomies Instead of 'category' => $catID, use 'tax_query' => array( array( 'taxonomy' => 'series', 'field' => 'term_id', 'terms' => $catID, ...


1

You have one or two problems here is_category() should be object of $query in your example code get_query_var('post_type') will always return false on a category page AFAIK, so that code is totally unnecessary Just a tip, when using pre_get_posts with any type of archive, also check for non admin pages as your back end will also be affected by this change ...


0

For creating taxonomy like category & tags for custom post type use register_taxonomy wordpress function Refer this wordpress codex for register_taxonomy


0

Filters and Actions The hooks you can chose to run whatever limits the post content length from, is either save_post, save_post_{post_type} or edit_post (or both) (the following actions are executed inside wp_publish_post() /** This action is documented in wp-includes/post.php */ do_action( 'edit_post', $post->ID, $post ); do_action( ...


0

Can you provide a link to your site and a little more explanation on what you are trying to achieve? Here's a shot in the dark guess. Archives shows content of type 'post', but you can alter it to include custom post types. Add this filter to your functions.php file: function namespace_add_custom_types( $query ) { if( is_category() || is_tag() && ...


0

I'm a bit late to the game, but I thought it was worth noting for future reference that your custom post type is called "wrestler_profiles" and your template is "single-wrestler.php." Your template should be named "single-wrestler_profiles.php" to match your custom post type name. As per the template hierarchy ...


0

My solution was to store the term order as metadata for the post. //reset terms if( is_array( $_POST['genres'] ) && count( $_POST['genres'] ) ){ $_POST['genres_order'] = ( $_POST['genres'] = array_map( 'intval', $_POST['genres'] ) ); wp_set_object_terms( $_POST['ID'], $_POST['genres'], 'nv_genre', false ); //will replace any previous genres ...


7

If we peek into the global $wp_taxonomies variable we see the associated object types. There might be better ways to do this or even core functions, but you could try the following: function wpse_172645_get_post_types_by_taxonomy( $tax = 'category' ) { global $wp_taxonomies; return ( isset( $wp_taxonomies[$tax] ) ) ? ...


5

You can do the reverse with get_object_taxonomies. Combine it with get_post_types to iterate over post types to check the taxonomies registered for each. EDIT- Here's an example that produces the same output as @birgire's function, without using dirty globals. function wpse_172645_get_post_types_by_taxonomy( $tax = 'category' ){ $out = array(); ...


0

I've configure permastructure for posts to /blog/%postname%/, I've created a page with slug about-us and I used the code bellow to register team_member CPT and it is working. I think you had a extra "/" in the rewrite argument. Also, you don't need to works with global $wp_rewrite; if you set the rewrite argument when the post type is registered, WordPress ...


1

I looks like you are using the custom meta boxes and fields github repo, which is an awesome library. I think the primary thing you need to do is a new WP_Query. Below is an example of that in action. The only difference is that in my example I made the "Assign to Homepage" a checkbox on the custom post type. <?php $args = array( 'post_type' => ...


1

Query for post type listing_type and author ID within your loop: $args = array( 'post_type' => 'listing_type', 'author' => get_the_author_meta( 'ID' ) ); $listing_post = new WP_Query( $args ); if( $listing_post->have_posts() ){ while( $listing_post->have_posts() ){ $listing_post->the_post(); the_permalink(); } ...


0

Turns out custom post type archieve files for CPTs like adventure, were still in my system (thanks to Dropbox messing up the file sync). So, this is why I was still seeing some of the template names listed in Page Attributes. Lesson learned for anyone going through the same issue: always make sure the files are completely gone from your local or server.


0

Personally I would not recommend making any such changes to the default way the Wordpress editor works as it could pose issues in the future. However, I think you may be able to accomplish this with some Javascript/jQuery. Take a look at this example. Make sure to test suggested implementation thoroughly, I have not tested it.


0

Use add_rewrite_rule() function custom_rewrite_rule() { add_rewrite_rule('^nutrition/([^/]*)/([^/]*)/?','index.php?page_id=12&food=$matches[1]&variety=$matches[2]','top'); } add_action('init', 'custom_rewrite_rule', 10, 0); you can use if ( 'myposttype' == $post->post_type ){} to make it post type specific. Weather you want to ...


0

There's a problem with your regex: product/(.+)/(.+)/(.+)/(.+)/?$ The .+ part says to match anything as many times as possible. The anything can include /'. If you used something like product/([^/]+/)+([^/]+)/?$ breaking this down, we have: product/ which matches product/ ([^/]+/)+? - which matches as few as possible, but at least 1, slug/ elements ...


-1

You Can Display you custom post type using this method your pagination can work !!! <?php query_posts( array( 'post_type' => 'post', 'posts_per_page' => '2', 'paged' => get_query_var( 'paged' ) ) ); if (have_posts() ) : while (have_posts() ) : the_post(); ?> <!-- Start your post. Below an example: --> <div ...


1

The second parameter to wp_editor is the value that the "id" attribute of the textarea element will have, and that is probably why there are such restrictions on it. By default it is also used for the "name" attribute but you can set it explicitly by using the $settings parameter to wp_editor wp_editor($ID, 'media_desc_n',array('textarea_name' => ...


1

When you use wp_list_categories() you get a list of terms, each one linked to its archive page. I think what you need is a form to filter the products, not a list of archive term links, so you can keep the selected filters between requests, for example, using $_POST, $_SESSION or $_COOKIES. Example using $_POST: <?php //taxonomies you want to filter ...


0

In a random query you will get duplicates between two different draws. Since each draw is independently random from the other, there is no much meaning to paging. If you set the random seed to constant then it is not random any more and you get paging working. Storing the seed in a cookie means that there is randomness for different users but not for the ...


0

Solved it for different edit pages for different roles. In my method resposible for rendering the field I have: if ( count( array_intersect( $allowed_editors, $user->roles ) ) < 1 ) $readonly = 'readonly'; Which I later use to either set the input field as readonly or add/remove classes before rendering it. Still working for the different ...


0

As @bonger commented, there is no custom post type filter despite what you've read. To use this filter for a specific post type, the best way is to use the post_row_actions filter and then test against the passed in $post->post_type. I've used the code below to add links to the actions row for a specific post type (in this case, myposttype). This will ...


0

Well, that was sutpid of me not to have seen this, but I just have to follow the tutorial and not use get_template_parts()! Moving on.


2

In typical use cases the performance cost of booting WordPress core for page load is significantly higher than querying for data. In other words it doesn't quite matter, because it won't be a bottleneck. You have to estimate: How close your data is to native WordPress concepts How much work (if any) it would be required to put it in such representation ...


3

See the codex re Meta Query. For example, this would get all posts at least a day old: $date = date('Y-m-d H:i:s',strtotime("-1 days")); // 1 day ago meta_query' => array( array( 'key' => 'name of your key', 'value' => $date, 'compare' => '<=', 'type' => ...


0

Turns our I needed to use the Tax Query to target the category... ugh. <?php $myposts = get_posts(array( 'showposts' => -1, 'post_type' => 'forms', 'tax_query' => array( array( 'taxonomy' => 'product_category', 'field' => 'slug', 'terms' => array('appeals')) )) ); foreach ($myposts as ...


0

Try this: $the_query = new WP_Query($args = array( 'post_type' => 'forms', 'tax_query' => array( array( 'taxonomy' => 'form_category', 'field' => 'slug' ), ), ) ); btw - Why do you have a 0 in this add_action? Remove it or change it to > 0. add_action( 'init', ...


0

I hadn't tried this in practice, but theoretically should be easy. post_parent argument in query set to 0 should limit it to parent items, see Post & Page Parameters. Use pre_get_posts hook to correctly adjust main query, adding that argument.


1

It seems like you're actually asking three questions here; it's likely your question will be put on hold because of this. Why do you need to add a custom post type? If you're interested in learning how to develop for WP you can skip the plugin for members and instead read the WP Codex entry on user roles and capabilities; this will let you limit who has ...


0

Yes, you'll want to create custom metaboxes for those. This is a pretty good intro into how to do that. But you might want to think through a few things: Are you sure you want that added to ALL posts? If not, perhaps create a custom post type and attach those fields to that post type instead. Maybe you really DO want it on Posts and not a Custom Post Type, ...


0

You can use a conditional tag with the pre_get_posts action hook like this from your functions file. add_action( 'pre_get_posts', 'vm_get_shows' ); function vm_get_shows ( $query ) { if ( !is_admin() && $query->is_main_query() && is_home() ) { $query->set('post_type', 'shows' ); } }


0

In all honesty, I really think that all your misery is caused by your pagination function as we have briefly discussed a while ago. You do have a couple of issues here that are contributing factor to the problems you are experiencing Changing the main query for a custom query for what ever reason is almost always a big headache and should be avoided at ...


0

I ended up writing a basic function which used preg_match_all and preg_replace to find my short-code tags and sanitize the content before building the HTML output for the template page. In my case, only useful if you have the one short tag being used. function img_strip($str) { $preg = '/\[\bimg\b\](.*?)\[\/\bimg\b\]/'; preg_match_all($preg, ...


0

Yes, there is number of hooks in generic low level update_metadata() function. Limited to the post meta you would probably want to use update_postmeta or updated_postmeta.


0

First, WordPress does not offer any built-in solution to displaying posts of a specific post type and a specific taxonomy term. I'm talking about something like get_term_archive_link_for_post_type( $term, $post_type ) or so. So you have to do this yourself. Of course, you could create a page, name it Construction Projects, give it a new page template, in ...


0

You can use the do_shortcode() function for this. echo do_shortcode( '[your-shortcode including="any" parameters="needed"]' );


0

There is an example in the WP Codex which should work for you: Try the following naming convention for your taxonomy term archive template: taxonomy-{taxonomy}-{term}.php So, let's say you have a CPT named "Projects," a taxonomy named "Maintenance," and a term within the taxonomy named "Professional." Then your naming convention would be: ...


0

The top most terms, also known as the parents, has a parent value of 0. Any other term that has a value other than 0 set as the parent is a child term of that specific term which ID is set as parent If you look at the get_terms() documentation, you can make use of this parent parameter parent (integer) Get direct children of this term (only terms ...



Top 50 recent answers are included