Tag Info

New answers tagged

1

What you need to use here is the WP_Comment_Query() function. So on the author.php page, you can easily get the author info and ID as followed: // get author info $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author)); // set ID $user_id = $curauth->ID; Then we add the user ID in the query ...


0

You can add button via add_meta_box function. function add_your_meta_box(){ add_meta_box('your-metabox-id', 'Title', 'function_of_metabox', 'custom_post_type', 'side', 'high');} add_action('add_meta_boxes', 'add_your_meta_box'); function function_of_metabox() {?> <input type="submit" class="button button-primary button-large" value="Add New" ...


1

It appears to be because I was using the Advanced Custom Fields plugin, which has a seperate taxonomy option that was overriding the standard.


0

I don't know if you would consider using a plugin – but I recently stumbled upon the plugin ultimate member and it seems it can do a lot of things with user profiles, but also seems to be suitable to display user's comments on the profile page: • "Show author posts & comments on user profiles"


2

Like this: function custom_js_to_head() { ?> <script> jQuery(function(){ jQuery("body.post-type-YOUR-CUSTOM-POST-TYPE .wrap h1").append('<a href="index.php?param=your-action" class="page-title-action">Import from ...</a>'); }); </script> <?php } add_action('admin_head', 'custom_js_to_head'); ...


1

You could try creating a custom post type for videos paired with a custom taxonomy that matches the personalities. Then you create the videos, categorize/tag them to the personality. Once they are tagged, create a template for the personality, write a custom WP_Query() that grabs your video posts filtered by the personality slug.


1

You're setting the HTML of the second drop down to essentially blank with: $('select[name="second_dropwdown"]').html("<option>Sorry, no options</option>"); So when you enable it again, that's the only option. Instead, you might try including that as an actual option within your select and then selecting it when disabling the second drop down. ...


1

I learned from the comments by @Pieter Goosen and @Ignat.B, and @Pieter Goosen's answer here, that I need to register the taxonomy on plugin activation, and insert the term. Then I need to hook the taxonomy registration code to the init action hook as suggested by the codex. This will ensure that when I insert the term on plugin activation, I have the ...


0

Try this code (maybe working) , but i'am not sure cause not testing : function amin_show_expire(){ global $wpdb; $result = $wpdb->get_results("SELECT * FROM wp_posts WHERE post_type = 'CUSTOM' AND post_status = 'publish'"); if( !empty($result)) foreach ($result as $a){ $show_time = get_the_time("Y-m-d", $a->ID ); ...


1

First method, you are missing the second parameter for get_the_author_meta, which is the ID of the author. Second method, you are using undefined variables.. Check this code, should get you what you want. // Method 1 <ul class="authpcom"> <?php $queried_object = get_queried_object(); $author_email = get_the_author_meta( ...


0

Try this.. This is a pretty basic code and you might need to modify it to get it fully work, but it will get you started. function load_testimonials( $atts ) { extract( shortcode_atts( array( 'id' => '', ), $atts ) ); $out = '<div id="testimonials" class="flexslider">'; $out .= '<ul ...


0

I found the answer. I had searched high and low yesterday, but today I finally found it: http://wordpress.stackexchange.com/a/143837/10595 add_action('template_redirect', function() { if ( is_singular('posttype') ) { global $wp_query; $page = (int) $wp_query->get('page'); if ( $page > 1 ) { // convert 'page' to 'paged' ...


0

when registering the post type , try 'exclude_from_search' => false,


2

No need to reinvent the wheel - put your editor support back and tweak the settings: function wpse_199918_wp_editor_settings( $settings, $editor_id ) { if ( $editor_id === 'content' && get_current_screen()->post_type === 'custom_post_type' ) { $settings['tinymce'] = false; $settings['quicktags'] = false; ...


2

register_activation_hook is one-time only activation hook. It can be used for database structure creation, as example, that needs to fire only on plugin activation trigger. In order to set a custom taxonomy you need a hook that will fire not just once, but per every WordPress load. Such as init. Use add_action( 'init', 'YOUR_CALLBACK' ); to achieve that


9

singular.php is basically an extra fallback for all post types, regardless if built-in or custom. It comes in straight after single.php and page.php, so you can omit the latter two templates and just have a singular.php template which will be used by all post types in single view. How useful it will be and the necessity of it will, just as with any other ...


5

It's the nature of the WordPress template hierarchy - point being, if you don't have a page.php, it will use singular.php, same if you don't have single.php, it will fallback to a template lower in the hierarchy. Ideal for themes that have the same layout for posts/pages, instead of having duplicate code in each respective template.


0

I don't think we can do that as a page in Wordpress, but I have another idea.. You can add a new taxonomy for your posttype template, like categories, then create a custom field for your posttype, (do the metabox) to show templates.


1

Plugins that load the WordPress environment this way get rejected from the repository, as they are prone to failure in non-standard configurations. For something like this I would use the admin-post-$action to receive requests. The WordPress API will be available where you can check if users are authorized to perform specific actions.


0

The previous answer is not working for me and I think it can not work for most people. Even if it works for someone, it overrides the WordPress configuration site-wide and it is not specific for the required custom post type. For me, the correct way to enable comments in a custom post type and remove the comments status meta box is something like this ...


1

In this situation I would use the page as a placeholder to configure the sidebars, even though WordPress will completely ignore it on the front end. Just add the page, make sure the slug is trainings, let the client set it up as they need, and then in your template: if ( $trainings_page = get_page_by_path( 'trainings' ) ) { $acf_sidebars_data = ...


1

Considering WordPress Codex flush_rewrite_rules This function is useful when used with custom post types as it allows for automatic flushing of the WordPress rewrite rules (usually needs to be done manually for new custom post types). However, this is an expensive operation so it should only be used when absolutely necessary.... I'd recommend you to ...


0

You can use the the acf/save_post action to copy the content from your custom 'full_text' field over to the normal post content field, so it can automatically be accessed by toc+ and other plugins. add_action( 'acf/save_post', 'wpse199256', 20 ); function wpse199256( $post_ID ) { global $wpdb; $post = get_post( $post_ID ); $wpdb->update( ...


0

pre_get_posts filters will be applied to all queries on a page- the main query, menus, and additional WP_Query instances. To target only the main query, use is_main_query(): function my_pre_get_posts( $query ) { // bail early if is in admin // or if query is not main query if( is_admin() || !$query->is_main_query() ) { return; } ...


7

First of all you really shouldn't be using query_posts(). Read this excellent explanation why. Then this is a perfect use case for transients. You just get the post once and then cache it for 24 hours using the Transients API. if ( false === ( $quotes = get_transient( 'random_quote' ) ) ) { // It wasn't there, so regenerate the data and save the ...


1

I was able to solve this by defining a rewrite rule: function rewrite_rules($rules) { $newRules = array(); $newRules['states/(.+)/(.+?)$'] = 'index.php?district=$matches[2]'; return array_merge($newRules, $rules); } add_filter('rewrite_rules_array', __NAMESPACE__ . '\\rewrite_rules');


0

@ialocin many many thanks. I have got it to work. Here is my full code based on yours: <?php $args = array( 'post_type' => 'portfolio', 'portfolio-category' => 'featured', 'posts_per_page' => -1 ); $loop = new WP_Query( $args ); $loop_posts = $loop->posts; $loop_posts_ids = wp_list_pluck( $loop_posts, 'ID' ); ...


0

This isn't really a WordPress question, but since you're using the Loop, a lot of people will assume it's WordPress-specific. That being said, the solution is to use PHP's native array-to-string conversion utilities. Instead of the code you do have, you'll want to use something like: <?php $posts = get_field( 'author_name' ); if ( $posts ) { echo ...


1

You can just get the terms from the current query. To achieve this you can use wp_get_object_terms(), but it expects IDs, which we can extract by using wp_list_pluck() on the query objects posts property. It seems like you only need the names, which we can extract again with wp_list_pluck() from the result wp_get_object_terms() returns. Last but not least, ...


1

Create single-yourcostomposttypename.php file in theme folder.


1

Typically when you want to create an extra representation or variation it implies extending URL a bit and treating that case differently. The easiest way in WP for that are rewrite endpoints. However the ease is relative you still need to handle with code the changes in a query and how to produce output. WP doesn't have an easy native concept of multiple ...


0

You dont have to make a post type Contact.Just make a dynamic sidebar in the Widget area of Wordpress.And take the Text Widget in that Dynamic Sidebar , Copy your html and Paste it there in the Dynamic Widget Area you make. If you are not able to make the Dynamc sidebar Paste ths code in you functon.php register_sidebar( array( 'name' => ...


0

Ok I finally notice what is it that I have to do! :D The variable was already set in the array in the shortcode atts. All I had to do was set the parent=$category in the before the filter: $terms = get_terms('cat_portfolio', array('hide_empty'=> true, 'parent'=> $category)); For wordpress developers maybe this is very easy but I am learning. Hope ...


0

You can try this solved your problems: add_action('admin_head', 'my_admin_custom_styles'); function my_admin_custom_styles() { $output_css = '<style type="text/css"> .column-date { display: none }; .column-tags { display: none }; .column-author { width:30px !important; overflow:hidden }; .column-categories { ...


0

I think that the whole concept of this question is a little bit wrong. The thing about custom post types is that they don't have categories like regular posts. They have taxonomies and terms. In fact regular categories are also a taxonomy for regular posts. So answering your questions, you need to know the name of the taxonomy first. The simple way is to ...


1

Look at the declaration of the function the_title(), it prints the title, if the third parameter $echo is set to TRUE which is the default: /** * Display or retrieve the current post title with optional content. * * @since 0.71 * * @param string $before Optional. Content to prepend to the title. * @param string $after Optional. Content to append to ...


0

First get the posts that have the taxonomy you need $posts = get_posts('resource type' => 'archive') Then loop the results and use this function wp_get_post_terms($post_id) I think you got it figured out how to display your results


0

you may try to de-register/unset default post type and register post type with your requirements. if ( ! function_exists( 'unset_default_post' ) ) : function unset_default_post( ) { global $wp_post_types; $post_type = 'post'; if ( isset( $wp_post_types[ $post_type ] ) ) { unset( $wp_post_types[ $post_type ] ); return true; } ...


0

wp_get_post_categories can only get POST categories not a custom post's categories, try this instead: $category = get_the_terms( $post->ID, 'custom-taxonomy-here' ); foreach ( $category as $cat){ echo $cat->name; } Check this link


3

I use template_redirect hook for this purpose. I suppose rented in your question is not taxonomy itself, but one term of some taxonomy. function my_page_template_redirect() { if( is_singular( 'rentals' ) && has_term('rented', 'your taxonomy name') ) { wp_redirect( home_url(), 301 ); exit(); } } add_action( ...


1

WordPress as a content management system organizes pieces of data into categorizations. It calls any individual piece of data that it might manipulate or display a "post", and any way to classify or organize that piece of data a "taxonomy". But not every post is the same, and there are often groups of posts that have a distinct set of properties that are ...


0

If you have registered that CPT and added uploads functionality, then you can write email functionality in that only. However, if it comes from any other plugin or theme, then either you will need to edit its code or create a plugin if sufficient hook is available. If there is no custom hook available and you are going to use some generic WordPress hook ...


0

If you just want to list them you can use the get_terms function: $terms = get_terms( 'my_taxonomy' ); if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){ echo '<ul>'; foreach ( $terms as $term ) { echo '<li>' . $term->name . '</li>'; } echo '</ul>'; } Read the codex, it has a lot of examples: ...


0

As per the ACF documentation, you must pass either the term and term ID or the term object to the get_fields() function for a taxonomy. So in your case, you would replace $tag_image = get_field('tag_image'); with: $tag_image = get_field('tag_image', $term);


2

Simply use get_sub_field("session_speaker"); function to retrieve that data. As you've said this is a relational field, it will return an array of post objects according to the docs. In order to get data from each speaker, you need to loop through the resulting array. Example: $speakers = get_sub_field("session_speaker"); if ($speakers && ...


0

You mentioned you are using a custom taxonomy - therefore including the cat key in your wp_query args won't work. wp_query expects that to be the ID of a term belonging to the standard WP category taxonomy. With a custom tax you need to use the dedicated taxonomy parameters. So your args should be something like: $post_args = array( 'post_type' => ...


0

The code contained the line add_action( 'admin_init', 'my_admin' ); at the end, but my_admin wasn't declared anywhere. Changed it to all_post_types, my function to register all the custom post types at once and it worked.


0

Ok, found the issue. By analizing the generated query, I realized that it rightly searched for current language posts. I'm currently use polylang as the multilingual plugin, and it correctly associate posts with a 'language' taxonomy. Now, I had far more 10 project posts but only 10 where of the current language. All fine now.


0

add_action( 'edit_form_after_title', 'my_edit_form_after_title'); function my_edit_form_after_title($post) { $post_types = array( 'page' ); // post type / s $templates = array( 'template-custom.php' ); // not edit :D if( !in_array( $post->post_type, $post_types) ) return; if( !in_array( get_page_template_slug(), $templates) ) return; ...


0

To display 'news', you'll have to add it to your loop arguments: $wp_query->query( 'post_type' => 'news', 'posts_per_page='.get_option('posts_per_page').'&paged='.$paged );



Top 50 recent answers are included