Tag Info

New answers tagged

0

Two things! 1) Don't use query_posts()! Instead, for situations like this, use the pre_get_posts action to modify the query. 2) I don't think you actually want to be using a loop here at all (so neither query_posts() nor pre_get_posts or even WP_Query). Rather, I think you're looking for wp_list_categories. In your template, you'd probably do something ...


1

The code you need will vary slightly depending on whether the Conference field is storing a text string (like "Big Ten") vs. the ID of the Conference post. I'll include both: Text String Example // place this code inside the loop of your single-team template $conference_name = get_post_meta( get_the_id(), 'conference', true ); $conference = ...


0

As you can read in the WordPress Codex, you have to write your own save function for any meta box anyways. So instead of saving those values with a function like update_post_meta(), you could simply implement your own saving function using another table. But you also have to write a corresponding load function, as the using get_post_meta() function in the ...


0

Solved. Had a custom author drop down function that causes a large query loop. add_filter('wp_dropdown_users', 'cust_dropdown_users'); function cust_dropdown_users($output) { $users = get_users(); $output = "<select id=\"post_author_override\" name=\"post_author_override\" class=\"\">"; //Leave the admin in the list $output .= ...


1

Use this one. Notice 'menu_name' field says Jobs now. // Register Custom Post Type function custom_post_type() { $labels = array( 'name' => _x( 'Jobs', 'Post Type General Name', 'text_domain' ), 'singular_name' => _x( 'job', 'Post Type Singular Name', 'text_domain' ), 'menu_name' => __( 'Jobs', ...


0

In case it helps anyone... I had misunderstood - the feeds argument of 'rewrite' was merely about the formatting of feed URLs (to use rewriting). What I want is not to have a feed URL output in the <head> of my custom post type pages. The only way I have found to do this, is using remove_action( 'wp_head', 'feed_links_extra', 3 ); although this ...


0

Still sounds something went wrong with your rewrite rules, try adding flush_rewrite_rules() at the end of your function that contains the registrations calls you posted in your questions. Like this: flush_rewrite_rules( false ); Setting the parameter $hard to false means you won't update the .htaccess and just do a update of the rewrite_rules transient. ...


0

I've tested your code and it works perfectly if you register the post type in the init action hook. In your code I don't see the action hook where you register the post type. Cna you try this? (remember to flush rewirte rules after update the code. Note that I remove the undefined variable $labels in the $args array for taxonomies): add_action('init', ...


0

To add query strings to post permalink you should use the post_link filter in combination with the add_query_arg function. add_filter( 'post_link', 'cyb_append_query_string', 10, 3 ); function cyb_append_query_string( $url, $post, $leavename ) { //Change for the post type you want if ( $post->post_type == 'home' ) { $url = add_query_arg( ...


0

Note to curators/admin: I wanted to leave a comment but I didn't have enough reputation. I know I am not formally providing an answer, but attempting to help the person asking the question along. Are you using any membership plugins? Can you give us a little more information on the overall site map and functionality? We are seeing a very narrow field of a ...


0

You could try this, IF the current user is logged in AND not Adminstrator it will pull all posts from the current user, otherwise it should default and show all posts from all users. <?php function filter_posts_by_author( $query ) { if( is_user_logged_in() ) { if( !current_user_can( 'administrator' ) ) { global ...


1

I really think that you have over complicated things here. Here is how I would treat the matter First of all, create a custom post type (which you have already done) Assign a custom taxonomy to it Convert all the posts from the listas-2 category to your created custom post type. See this post on how to Re-assign your custom taxonomy to these converted ...


0

Wordpress, by default don't enable comments on custom post types, and once you have added support for comments, you still get the following message: Comments are closed You have to basically manually visit each custom post and enable comments in the post editor screen. There are however a workaround to enable comments by default in bulk. You can use the ...


0

You can't use double sorting option. You can try this code once: add_action( 'pre_get_posts', 'fetch_staff_people' ); function fetch_staff_people( $query ) { if ( is_post_type_archive('staff') && $query->is_main_query() ) { $query->set( 'post_per_page', '-1' ); $query->set( 'meta_key', '_staff_purpose' ); ...


1

I think you forgot to check if $the_query have posts. <?php $args = array( 'post_type' => 'testimonials', 'posts_per_page' => 1, 'orderby' => 'rand' ); $the_query = new WP_Query( $args ); ?> <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ...


0

How are you currently generating the login URL & handling the redirect? You should simply be using wp_loginout and passing the permalink as the redirect, and let WordPress handle everything else: <?php wp_loginout( get_permalink() ) ?> Or for a more custom implementation: <?php if ( ! is_user_logged_in() ) : ?> <a href="<?php ...


0

For serializing and unserializing Data in Wordpress, you can use maybe_unserialize and maybe_serialize. If you want to handle the data and add/change values, you could use something like this: $metaarray = maybe_unserialize(get_post_meta($post_id,'_ait-dir-item',TRUE)); //now $metaarray has an array, if it is serialized. If not, $metaarray has a string. ...


0

You should first run the wp_insert_post() which will return the post ID. Then use that post ID to add your custom fields. Use add_post_meta() to add the custom fields. $post_id = wp_insert_post( $args ); add_post_meta( $post_id, 'longitude', $my_long ); add_post_meta( $post_id, 'latitude', $my_lat );


0

I think the solution is very easy. After registering you post type: register_post_type( 'portfolio', $args ); flush_rewrite_rules(); flush_rewrite_rules will do it for you!


1

You have inserted wrong thumb functions for large fancybox image URLs. <a href="<?php get_the_post_thumbnail(); ?>" class="project-img fancybox"></a> This get_the_post_thumbnail() returns an HTML image element but you need URL of image. Your first code should be like this. <?php $args = array( 'post_type' => 'portfolio' ); $loop = ...


0

If I understand you correctly, you need to show all posts from a term when a term's page is being displayed. Before I answer the real question, there are a few points I would like to highlight since you are new to Wordpress Never use hyphens (-) to separate names in custom post type names and custom taxonomy names. They are extremely troublesome later, ...


1

orderby does not accept the values ASC or DESC. These are acceptable values for the parameter order. Changing 'orderby' => 'rand' to 'order' => 'ASC' should be sufficient and should by rule work As already pointed out, if (have_posts() ): should be if ($the_query->have_posts() ): Apart from that little discrepancy, you code have to work It ...


0

I solved the issue very easy. $type = array('event','post'); $args=array( 'post_type' => $type, 'category' => '8', 'post_status' => 'publish', 'posts_per_page' => 5, 'caller_get_posts'=> 1); These gets all custom posts 'event' and normal posts from category 8. ...


-1

<?php the_post(); // $postType holds all the information of the post type of the current post you are viewing $postType = get_post_type_object(get_post_type()); // $postSlug is the slug you defined in the rewrite column: about/team-members $postSlug = $postType->rewrite['slug']; // $datas = { [0] => 'about', [1] => 'team-members' } $datas = ...


0

A possible solution is whenever the custom post type is saved, you can set its' parent to be about/team-members prgrammatically. Here are the steps: You can use the save_post hook to 'catch' whenever someone tries to save a post. If that post is the custom post type you are after, then proceed. Make sure to set the custom post's parent to the page you ...


0

I had some more time to dig into this myself (sorry if I wasted anyone's time), and I figured that for me, the best way to solve the highlighting problem would be to kinda re-do what _wp_menu_item_classes_by_context() is doing, that is iterate over all parents and ancestors of the menu item that acts as the parent of my custom post type, and add classes ...


0

Disclaimer: After giving it a try this seems a not longer existing problem to me, because - at least for me - it just works on my WP 3.9.2 installation. Couldn't find a according bug tracker though. I have out together a little plugin to test this, which might help someone. But like I said in above disclaimer, I couldn't reproduce the problem in a current ...


0

I personally now use on every project Advanced Custom Fields (http://advancedcustomfields.com/), it is well-maintained, easy to manage, extremely powerful and ever-evolving in terms of features. It has a free and a Pro version (right now the plugin creator is moving towards a new version where there is only Pro, not single Add-Ons). Your repeater field would ...


0

Use this metabox addon in your plugin. It is easy to use and add


1

This may be an alternative for you. The Advanced Custom Fields plug in has an Image Field, which allows images to be uploaded and selected. You can set the field to show on your Custom Post Type pages and also integrate a line of code into your template file. You can create as many image fields as needed. Learn more about the Image field here.


0

i finally figured out a solution. I guess it's not the perfect one, because all posts are still looped and the wrong language just doesn't show, but for now it works. I am still open for ideas. My idea right now is to get the language of the post and don't display it if it doesn't match the pages language. Here's the new part. global $polylang; $postlang ...


0

just changed the query a little $meta_query_args=array( 'relation' => 'AND', array( 'key' => 'event-start-date', 'value' => $date_today, 'compare' => '<', ) ...


1

If you want an example of how to do the dropdown filtering using ajax, then if you factor out your taxonomy dropdown into your "functions.php": function my_dropdown_categories( $taxonomy, $current_selected = '', $include = null ) { // Get all terms of the chosen taxonomy $terms = get_terms($taxonomy, array('orderby' => 'name')); // our ...


0

Use jQuery action on first dropdown .. this is the code from your mentioned url .. You can populate the arrays using php functions ... function dynamic1(parent,child) { var parent_array = new Array(); // This is the default value parent_array[''] = ['Please select a manufacturer']; // All other elements // parent_array['PARENT NAME'] = ...


0

Single pages are designed to display a single post, and not an index of posts as an archive page would. I'm not really sure what are you trying to achieve here as well. It is always a bad idea to try and use a specific template for anything else than what it was intended for. The main query are quite specific to a specific template, in this case, the main ...


2

The correct way to register a taxonomy is to wait for the action registered_post_type, because that’s the only way to know that your post type actually exists. This action is fired when a post type was registered. Core post types are registered twice for reasons. You have to wait for the second call, because the rewrite object is not available earlier. If ...


0

From the register_taxonomy() codex page: Better be safe than sorry when registering custom taxonomies for custom post types. Use register_taxonomy_for_object_type() right after the function to interconnect them. Else you could run into minetraps where the post type isn't attached inside filter callback that run during parse_request or pre_get_posts. ...


0

Try this add_action( 'init', 'tag_synchro', 10 ); It might be the case that, when you set priority to 0 , your callback does not get called.


0

You are looking for function get_term_link. Example $my_term_link = get_term_link($cat_lists); Here $cat_lists is term object. Official Documentation


1

This might not answer your question, but you have a few issues with your code Do not use uppercase letters in function names, taxonomy names and custom post type names. Only use lowercase letters. Separate names with a underscore (_). Also, just a tip, never start these names with letters, or use a hyphen (-) to separate names Never use ...


0

Make the following modifications, I hope it will do the job function AppManager_custom_taxonomy() { $labels = array( 'name' => _x( 'App Categories', 'taxonomy general name' ), 'singular_name' => _x( 'App Category', 'taxonomy singular name' ), 'search_items' => __( 'Search App Categories' ), 'all_items' ...


1

It sounds like all you need to do is specify the 'post_type' argument which is only 'post' by default. $posts = get_posts( array( 'category' => 16, 'post_type' => array( 'post', '{another_post_type}', '{another_post_type}', '{another_post_type}' ) ) ); You might also consider using WP_Query to make a custom loop instead. That's a bit ...


0

I finally found the custom post type data. It is stored in the wp_post table where post_type = custom post type (e.g. "products"). The field (column) data is stored in wp_postmeta where the meta_key is the column name and meta_value is the column value. This query will bring back all data associated with the custom post type "products": SELECT P.ID, ...


1

What you want can be done. It's just not likely to be really clean and neat. You can accomplish this by using a custom Walker Class for the wp_nav_menu() when you insert it. class My_Walker_Class extends Walker_Nav_Menu { function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { $output .= sprintf( "\n<li><a ...


1

At the end of your code after the last } add : add_action('init,'products_post_type'); Make sure you're adding this to the file in the /wp-content/your_custom_theme/includes/theme-init.php file, and then of course update the permalink. With the CherryFramework, make sure you don't modify any of the files in the CherryFramework folder, or you'll lose out ...


1

Try adding: add_action( 'init', 'products_post_type' ); As you can see in the Codex example for register_post_type() you must add your function to the init hook, so that it is actually run. Otherwise, what you have, is a function that is defined, but never executed. If you did this with a default theme, then you were adding the function to an action ...


0

The problem is that you are passing a comma separated list of terms, not an array of term. For example, if you enter 'army,navy,airforce' in the custom field: $related = array ( get_post_meta($post->ID, 'related_categories', true) ); //$related = array('army,navy,airforce'); //What you need is //$related = array('army','navy,'airforce'); You need to ...


0

You can add all your post types in an array as a variable, and then pass that through a foreach loop $post_types = array('members','post','testimonial'); foreach ($post_types as $type) { if( $post_type == $type ) wp_enqueue_script( 'portfolio-admin-script', plugins_url( '/js/admin.js', __FILE__),'','', true); //"TRUE"-ADDS JS TO FOOTER }


0

You have to use OR(||) operator to test for each of the condition. OR returns true if any of the condition is true if ( ($post_type == 'members') || ($post_type == 'post') || ($post_type == 'testimonial') )


0

Try this: if( in_array($post_type, array( 'members','post','testimonial' ) ) ) wp_enqueue_script( 'portfolio-admin-script', plugins_url( '/js/admin.js', __FILE__),'','', true); } Function in_array is used to check if current post type is in the array of allowed post types.



Top 50 recent answers are included