Tag Info

New answers tagged

0

Hmmmm.... I'm not sure this is possible since the fairs are not located under the "past fairs" CPT. However, the URL structure shouldn't be too critical as long as the navigation on your site is setup in a way that makes sense. Is there any other reason you want this behavior other than personal preference?


0

This Code Creates a New Recent Posts Widget Which Includes Your CPT's There's 2 steps involved when extending the native recent posts widget: i. Create a new class for your custom recent posts widget which you can do by copying and renaming the recent posts widget code from the defaults-widgets.php in wp-includes folder. ii. Then you will need to register ...


1

You will need to use a WP Query to search for posts of that category. It will be something like: $author = get_the_author(); // defines your author ID if it is on the post in question $args = array( 'post_type' => 'book', 'post_status' => 'publish', 'author'=>$author, ...


1

What you want to do is not possible with pagination. I've been thinking about it and came up with this. This is how I will do it Get the current page you are on with $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; Run a custom query in which you get the first post, which will most probably be the newest one. Do a check to see if you are ...


0

You forgot to declare global $post //Create Meta box function astest_add_metabox() { add_meta_box("astestimonial_metaboxes", "AS-Testimonial Client Information", "astestimonial_meta_box", "astestimonial", "side", "low"); } add_action('add_meta_boxes','astest_add_metabox'); //html code function astestimonial_meta_box() { global $post; ...


1

This should get you going in the right direction. Not my solution, slightly modified from here. You'll need to swap out your-post-type for the post type you're using. function adjust_post_formats() { if (isset($_GET['post'])) { $post = get_post($_GET['post']); if ($post) $post_type = $post->post_type; } elseif ( ...


1

This is an answer I re-porpoised from a question that was abandoned. I thought this will help you solve this issue By default, all custom post types are excluded from the main query, that is why you don't see any posts when going to the front end author page. To accomplish this, you will need to modify the main query to include these post type/s. For this ...


2

Not to be rude, but you've missed everything here Firstly, you should never use query_posts to construct custom queries. This is not just my emphasis, but the codex as well. The one big problem with query_posts is, it many circumstances, pagination fails Note: This function isn't meant to be used by plugins or themes. As explained later, there are ...


1

your query_posts line uses $post_type which will only be the last post type in the $post_types array.


1

Ok - lets try this again :) I added the map_meta_cap parameter which is needed to have delete_others_posts work. Now I was able to get authors to edit and view all posts but only delete their own. $labels = array( 'name' => __( 'Book', 'textdomain' ), 'singular_name' => __( 'Book', 'textdomain' ), 'menu_name' => __( ...


1

As I already mentioned in my comments, you must use pre_get_posts to add custom post types to archive pages. One thing you must keep in mind here though, you have two archive pages here, archive.php and archive-event.php, so is_archive() is going to return true on both, which will alter both pages. You will need to exclude archive-event.php from your ...


0

As written here, you need to use two nested arrays in the tax_query argument. So, with your arguments it should look like this: $args = array ( 'post_type' => 'restaurants', 'tax_query' => array (array( 'taxonomy' => 'location', 'field' => 'slug', 'terms' => 'citya') ), 'order_by' => 'title', 'order' => 'ASC' ); If you only need to ...


0

I have managed to find a clean and simple way to achieve printing the taxonomy term assigned to the post with the following: <?php the_terms( $post->ID, 'TAXONOMY NAME', ' ', ' / ' ); ?> Using term retrieves the terms associated with the given object(s), in the supplied taxonomies. Here is a link to the codex with examples and further detail.


0

You should go and read Debugging in Wordpress, as this problem could be easily solved with debug set to true is_taxonomy() was depreciated in version 3.0 already, and has been replaced with is_tax( $taxonomy, $term ) You'll just need to specifiy your taxonomy and term in the parameters and you should be good to go


0

I think you are talking about terms, not categories. You can use wp_list_categories to retrieve and display the terms that a post belongs to. Here is a working example from the codex. Remember the $taxonomy variable can be changed to category or any custom taxonomy <?php $taxonomy = 'YOUR TAXONOMY NAME'; // get the term IDs assigned to post. ...


1

As Pages are a special built in Posttype, they get an own template hierarchy. Other "normal" post types and custom post types can only be templated by "single-$posttype.php". You can however hook into the single_template filter and make wordpress redirect to your template file: function get_custom_post_type_template($single_template) { global $post; ...


0

To follow up on @MZAweb's answer. You can also delete the term automatically like so: add_action( 'before_delete_post', 'cpk_delete_term' ); function cpk_delete_term( $post_id ) { $post = get_post( $post_id ); if ( term_exists( $post->post_title, 'YOUR_TAXONOMY_NAME' ) ) { $term = get_term_by( 'name', $post->post_title, 'YOUR_TAXONOMY_NAME' ...


0

Try looking at the permalinks settings as well as the portfolio settings. The permalinks settings allow you to create a custom URL-scheme that you can use for many post types. Although I don't know the exact theme you're using, many have options to customize the URL of the portfolio in a portfolio settings page. Finally, if none of those work, you can look ...


0

As far as I remember the appropriate query for all public post types is post_type equals string any. You can use get_post_types() to retrieve a list, but be careful with arguments, since not post types are meant for public/front display.


1

add_action( 'pre_get_posts', 'add_my_post_types_to_query' ); function add_my_post_types_to_query( $query ) { if ( is_home() && $query->is_main_query() ) $query->set( 'post_type', 'any' ); return $query; } refer to http://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters


0

By default, category archives only show posts of the default 'post' type. The below code should get it working how you want. —via CSS Tricks function namespace_add_custom_types( $query ) { if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) { $query->set( 'post_type', array( 'post', ...


0

If you say that it's all the same boxes and format anyway, I would create a custom text meta box on the edit page for their posts where they can just type the category (CSS class). That way they have control in the edit page for which category it belongs to at time of writing (or can easily go back through posts and change without any coding knowledge ...


0

As the dashboard uses the menu_position 2, just use menu_position 1. so: $args = array( 'label' => __( 'programmes', 'hiblio' ), 'description' => __( 'Programmes for application from partner organisations', 'hiblio' ), 'labels' => $labels, 'supports' => array( 'title', 'editor', ...


0

$terms = get_terms('location', array('orderby' => 'date', 'order' => 'ASC')); foreach( $terms as $term ) { $args = array( 'post_type' => $post_type, 'orderby' => 'date', 'order' => 'ASC', 'ignore_sticky_posts' => 1, 'post_status' => 'publish', ...


0

Right I have come at this from a different angle. I registered all the posts as normal. And then depending of the variable set it will remove the menu from the backend. function remove_menu_items() { global $brandChoice; if ( $brandChoice == 'brand1' ) { remove_menu_page( 'edit.php?post_type=cpt1' ); } else if ( $brandChoice == 'brand2' ...


0

I think the easiest way would be like this: Custom Taxonomy Issue Custom Post Type Article You can add custom fields to Taxonomies like described here: https://pippinsplugins.com/adding-custom-meta-fields-to-taxonomies/ This way, you get the relation between articles and issues, you can add information about the issue by the custom taxonomy fields, and ...


0

You need to check the information that their is in action variable. $action = (isset($_REQUEST['ac'])) ? $_REQUEST['ac'] : 'none'; var_dump("action: "+$action); With this line, you will be able to review it's content and you will see that you don't get the correct information. I guess that your dev database is out off synch with your local one. So, you ...


0

If you can get a dynamic variable value of the brand, then you can load wanted CPT. Inside function.php Create a link to your new function "remove_cpt_multisite". Ex: // Remove menu items for users include (TEMPLATEPATH . '/assets/functions/remove_cpt_multisite.php'); The template itself (remove_cpt_multisite.php) : <? add_action( ...


2

I would do something like OmAk suggested but I would add some fallback : $activists_thumbs = has_post_thumbnail() ? the_post_thumbnail() : 'path/img_fallback.jpg'; It's better to check if you have something before actually using it. EDIT: wp_reset_postdata() is enough (instead of wp_reset_query() )


1

I would create a custom post type of "tickets" - I find it easier to just use a CPT register plugin then remove it. You may prefer to code it yourself in which case plenty of information is available on the Codex. When that person clicks join use something like: //first define your post info $post = array( 'post_title' => 'Ticket for ...


1

Wanted: Add the ability to join/unjoint an event for registered client. Allow the admin to manage/review easily each event participants. Here is what I will do for a full management CMS Create a custom meta box that you will attach to your CPT "event". (this meta box will display the name of every person that are linked to the event, also, the ...


1

If I understood correctly, you want a archive template for terms of core tag taxonomy that includes only your portfolio custom post type. The best way is to use the pre_get_posts action hook to set post_type argument of the query to 'portfolio': add_action('pre_get_posts', 'query_post_type'); function query_post_type($query) { //Limit to main query, tag ...


0

You can try this way : set_post_thumbnail( $my_post_id, $thumbnail_id ); You have to add image into library first like this way : $uploaddir = wp_upload_dir(); $file = $_FILES[ ... whatever you have in your POST data ... ]; $uploadfile = $uploaddir['path'] . '/' . basename( $file ); move_uploaded_file( $file , $uploadfile ); $filename = basename( ...


3

You can make use of get_post_type( $post ) to check whether a post belongs to a certain post type Inside your loop, you can do the following check while ($my_query->have_posts()) : $my_query->the_post(); if ( 'activists' == get_post_type() ) { /* Custom code for 'activists' post type. */ } else { /* Custom code for the other post types. ...


0

You can use this: <a href="<?php the_permalink(); ?>" title="<?php echo the_title_attribute(); ?>"> <?php the_post_thumbnail(); ?> </a> This will place the featured image with a link to the main post. More details about how you can use image_size when calling the function: the_post_thumbnail


0

First, let me say that there is no web application 100% secure. That being said, you are using the nonce correctly. The function you are using, update_post_meta(), will sql-scape the data as it uses insert/update methods of wpdb class. So, there is no risk for most common security problemas. What you should take care, I think, is data validation, and you ...


1

The short answer is no. For the canonical example of why just take a look at native post types. They are registered twice during each page load: Quite early because of backwards compatibility reasons and plugins possibly expecting them to exist. On init because now locale things are actually loaded and post type definitions can be properly translated. So ...


0

You say that you know about show_in_menu parameter for register_post_type() but it seems like you missed the options for this parameter: 'false' - do not display in the admin menu 'true' - display as a top level menu 'some string' - If an existing top level page such as 'tools.php' or 'edit.php?post_type=page', the post type will be placed as a sub menu of ...


0

Update... I have gotten the following to work well :) <?php $terms = get_terms( 'industrygroups' ); echo '<div class="row">'; foreach ( $terms as $term ) { // The $term is an object, so we don't need to specify the $taxonomy. $term_link = get_term_link( $term ); // If there was an error, continue to the next term. if ( ...


4

I am not going to give any specific code but I will give you Idea how it can be done without creating any custom database table. I am assuming one driver per truck Algorithm Create two html list, make them sortable. Each list items represents a post type and have ID data field. Once sorting is done get all ids in order. Make two array one contains truck ...


0

Try this code add_action( 'pre_get_posts', 'as25_column_orderby' ); function as25_column_orderby( $orderby ) { if( ! is_admin() || 'lot' != $query->get( 'post_type' ) ) return; $orderby = $query->get( 'orderby' ); if( 'auction' == $orderby ) { $query->set( 'orderby', 'parent' ); } }


0

To retrieve all the terms in a taxonomy, you can make use of get_terms Here is an example from that page to retrieve the term names of a custom taxonomy $terms = get_terms('my_taxonomy', 'hide_empty=0'); if ( !empty( $terms ) && !is_wp_error( $terms ) ){ echo "<ul>"; foreach ( $terms as $term ) { echo "<li>" . ...


0

I was having the exact same problem on an archive page of a custom post type with a needless extra query; for pagination reasons. Searching for the same solution I found this post on Stack Overflow http://stackoverflow.com/questions/21303743/new-wp-query-or-pre-get-posts-to-view-all-posts-for-custom-post-type I had a play and added this line of code into ...


0

If I understand correctly, you want your CPTs to show on regular archive pages (cateogires, main query etc) but when searching only your CPTs you get again your CPTs with all regular posts etc.. Here is what I made and for now as I have seen it is working well, but you never know where you can get any error so here, try it and see if it works well for you. ...


1

I don't know of any WordPress-specific way to exclude duplicate-title posts from a query and I'm sure that there are multiple ways to address this. The solution that jumps to mind is to store each post title in an array and then check to see if that title is already there before outputting the post. Some quick untested code: <?php $args = array( ...


0

For now I've just redirected the default search string (www.sitedomain.com/?s=keyword) to www.sitedomain.com/trade/keyword, (trade is my custom taxonomy) although I'm pretty sure this isn't the correct or best way to do it so it'd be great if someone else has a better solution. Here is the code for redirecting the search string: function redirect_search() { ...


0

As brasofilo mentioned you can do a str_replace() on the admin_post_thumbnail_html filter. function changeFeaturedImageLinks($content) { $content = str_replace(__('Set featured image'), __('YOUR_CUSTOM_TEXT'), $content); $content = str_replace(__('Remove featured image'), __('YOUR_CUSTOM_TEXT'), $content); return $content; } ...


0

Well, maybe you shouldn't set $args['posts id'] as this is not a supported argument for the get_posts function and instead use the "posts__in" argument or instead switch to the "get_post" function if you get the id parameter. Also, i'm not quite sure but i think you have to use quotes in the shortcode. So your Shortcode function should look like this: ...


0

Use a new query outside the loop like this one $query = new WP_Query( 'category_name=ben affleck;post_type=post' ); if ( $query->have_posts() ) : while $query->have_posts() : $query->the_post(); // Loop output goes here endwhile; endif;



Top 50 recent answers are included