New answers tagged

0

Okay! Finally, I was able to make it work. Below is the complete working code. add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 2 ); // Grabs the inserted post data so you can modify it. function modify_post_title( $data ) { if($data['post_type'] == 'artist' && isset($_POST['acf']['field_573676a95d920'])) { // If the actual field ...


0

I figured it out: <?php $args = array( 'post_type' => 'faq'); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); ?> <div class="faq-wrap"> <div class="q-wrap"> <h3>&...


1

Yes, they will. You will find the WordPress template heirachy useful, particularly this graphic: This shows how the templating system works - in particular, how WordPress will select the most specific template it can find, with fallbacks to the least specific (eventually, to index.php). In your case, you'll see in there that single-$posttype.php falls ...


0

Just use the slug component of your rewrite argument for your custom taxonomy: register_taxonomy([ 'rewrite' => [ 'with_front' => false, 'slug' => 'cpt', ], // Other args ]);


1

Since it sounds like you're trying to do this without code I would do it this way: Create an 'Advertisement' post type which supports categories. Then use a 'Related Posts' widget that allows you to select custom post types as well as related categories. Possibly one of these And use the widget settings to call the appropriate Ad UPDATE: Not sure how clear ...


3

numberposts doesn't exist for WP_Query instead use "posts_per_page" => 1


1

Ok, my fault. I only have to add an argument when creating the custom post type, 'has_archive' => true. Thank you anyway for taking the time to read my question.


0

I don't know any other way There is a much, much better way to do this - custom fields. As per these instructions in the custom fields docs, let's say you use the field name iframe_url: <iframe src="<?php echo esc_url( get_post_meta( $post->ID, 'iframe_url', true ) ?>" width="960" height="540" frameborder="0" allowfullscreen="...


2

In WordPress 4.5.3, there's a foreach in wp-includes/post.php on line 1177 and no others around it, so I'm guessing this is the one that's triggering the error in your install on line 1172. This is inside the register_post_type() function, and it's looping through the taxonomies argument that you're sending through. Well... that you were meant to send ...


0

Managed to find the solution here Essentially, as I was using the Types plugin standard parent / child wordpress code wouldn't work


0

If I understand you correctly, you're basically wanting to grab one post from each taxonomy term. And then get that post's link. WP_Query is your friend here - with a custom query, you can get posts with almost any criteria you want (check the docs I've linked to there, they outline almost everything you can do). The criteria in this circumstance is a ...


1

You will need to store the field value in a variable and use the get_field() instead of the_field() function. From there you can introduce your own custom control structure to set the color you want. Here is a snippet <?php //store the value in a variable first $option = get_field("status"); if($option=="K dispozicii"){ ?> <...


0

this works for me : http://www.deluxeblogtips.com/2010/05/add-custom-column.html In my case I used this code : add_filter('manage_edit-projet_columns', 'my_columns'); function my_columns($columns) { $columns['categorie'] = 'Cat├ęgorie'; return $columns; } add_action('manage_posts_custom_column', 'my_show_columns'); function my_show_columns($name) { ...


0

Change the_field() to get_field() the_field() = echo get_field()


1

When you are concatenating string you shouldn't use ;after the method. Also you should close que quotes, call the method, and open again. Try the code below: $listItem .= '<div id="agenda-block-image-responsive" style="' .get_field('speaker-img' ) . '">';


0

date() PHP functions returns the value of time() PHP functions in the specified format. time() use server local time. If you want to get date/time based of WordPress configuration, you could use current_time(), a WordPress function, instead of native PHP functions. // 'timestamp' = Unix Timestamp or 'U' PHP time format $current_time = current_time( '...


0

For consistency, I'm assuming you'd prefer to use "Save" instead of "Publish" throughout Wordpress instead of just on the text of the button. Based on the solution provided by @Rarst, I expanded the code so it translates many (all?) other instances of the word "Publish" to the appropriate variation of "Save". add_filter("gettext", "...


1

You can't without hooking a filter to recognise the files in your plugin BUT you can hook into the template_include filter and register your own file e.g. add_filter('template_include', 'my_function_name'); function my_function_name( $template ) { if( is_post_type_archive( 'post_type' ) ){ $template = dirname( __FILE__ ) . '/templates/archive-post_type....


-1

Don't have the direct answer myself, partially because I don't know what you want to filter for. But did you check how some of the plugins do it? Here are two examples: Filter page by template, Parent page filter. As for your second question, not sure if that's possible. That also depends on how you have connected the form to the custom post type. You might ...


0

Turns out what I needed is to use "in_category" NOT "is_category". Here is the solution: <?php if (in_category(7)) { echo 'yes'; } else { echo 'no'; } ?>


0

Well, the problem is quite simple: it's publish, not published. According to the documentation: post_status (string / array) - use post status. Retrieves posts by Post Status. Default value is 'publish', but if the user is logged in, 'private' is added.


0

Use WP set object terms $new_post = array( 'post_title' => $title, 'post_content' => $description, 'tags_input' => array($tags), 'post_address' => array($address), 'post_status' => 'draft', // Choose: publish, preview, future, draft, etc. 'post_type' => 'trademen' //'...


0

After some research I found none of these answers are up to date. As of December 8, 2015 WordPress includes a new filter, register_post_type_args, which lets you hook into the arguments of a registered post type. function wp1482371_custom_post_type_args( $args, $post_type ) { if ( $post_type == "animal-species" ) { $args['rewrite'] = array( ...


4

get_post_format and get_post_type are completely different. Post Formats can be one of the following: 'standard' (default one) 'aside' 'chat' 'gallery' 'link' 'image' 'quote' 'status' 'video' 'audio' And shopping is the post type you have created and not post format. You can add post format for the post type(shopping) like this add_post_type_support( '...


0

Your code should work, it might be that your posts per page option in back end is set to 1. It would be beneficial to explicitely set posts_per_page in your query args. You can also make the code faster if you only need to know the amount of grandchild posts, you can just return the post ids's. Here is an example: (Copied and modified from your code) $...


0

You capability type is not valid. I would remove the code below if you can. WordPress auto generates the capability_type. "capability_type" => array( strtolower($s), strtolower($m) ), Check out the documentation for capability_type. https://codex.wordpress.org/Function_Reference/register_post_type


0

Seems like I just need to set has_archive to a string instead of true with the desired slug, in my case archive/dogs. Then, create a page with the dogs slug and set the desired template to it.


2

I found solution! A Monkeyman Rewrite Analyzur plugin was very helpful: https://wordpress.org/plugins/monkeyman-rewrite-analyzer/ So now, I have such working urls... single.php: /magazine-name/issue-year/issue/article-name archive.php: /magazine-name/issue-year/issue /magazine-name/issue-year /magazine-name On a custom post editor page in wp-admin I ...


0

You need an action called manage_$post_type_posts_custom_column. This will allow you to add columns to your custom posts page. To be more precise, you need a filter to generate the column and an action to fill it with content. In your case something like this (untested): add_filter( 'manage_chimpmunks_posts_columns', 'set_custom_size_column' ); add_action( '...


0

You can use the body's classes : body.single-artist #main{ background-color:red; }


0

Collapse the <div id="main">. I hope that you have <article> tag which id and class attributes like below <article id="post-212" class="post-212 post type-post status-publish format-video has-post-thumbnail hentry category-resources post_format-post-format-video active"> Inside the class attribute you can find the post type as type-post, ...


1

As of WP 3.7 (https://core.trac.wordpress.org/ticket/14206) you can add this argument to register_taxonomy: 'meta_box_cb' => 'post_categories_meta_box' to get the built-in checkbox category style metabox without having to make your taxonomy hierarchical. Also you could instead provide your own callback function to create your own metabox (i.e. with a ...


0

I used Pods along with Flexslider http://flexslider.woothemes.com/ Flexslider markup is an HTML list. A Pods loop generates the list of images (in my case). Add the Flexslider JS in the appropriate place for the animation and you're good to go. Most plugins don't provide a way to programmatically generate the list, but this way you can. My implementation ...


-1

Which plugin you're using for the contact form? It looks likeyou're thinking about Gravity forms. You can create it with a custom function when the action gform_after_submission is fired - https://www.gravityhelp.com/documentation/article/gform_after_submission/ For Contact form 7, there is another hook, see here: wpcf7_before_send_mail, wpcf7_mail_sent ...


0

Sounds very simple as querying for posts and iterating through the results and working with the post status.. Just make sure to add 'post_status' => 'any' to the query args so as to include more statuses beside the published: $args = array( 'author' => 1, // user ID here 'posts_per_page' => -1, // retrieve all 'post_type' => 'post', /...


0

This is not something that WordPress can easily do. You can think of pagination in WP as sliding window that shows fixed size part of one large query. It can be at start of the query or at the end, but it relies on it being same query. This doesn't nearly work when the size and number of the page are subject to variable logic like this. I had recently ...


0

wp_list_pages calls get_pages internally and pass the argument list to get_pages so you can pass arguments whatever get_pages accept. To display child posts on your single-{post_type}.php you need to call wp_list_pages with post_type parameter. wp_list_pages will ignore post_type but it will pass this to get_pages. Example:- echo '<ul>'; ...


0

Your post type (member_post) doesn't match your template slug (memberPost). Whichever you choose, it must be all lower case.


2

File should be single-member_post.php instead of single-memberPost.php. In single-{posttype} , {post_type} is the $post_type argument of the register_post_type() function. Never use flush_rewrite_rules(); in init use it only on theme/plugin deactivate or activate. Since this is a theme you can use it on after_switch_theme hook. add_action( 'init', '...


0

If you want the terms ordered by slug rather than name then use this... <?php if(has_term('', 'CUSTOM-TAX')) {?> <?php $custom_terms = get_the_terms( get_the_ID(), 'CUSTOM-TAX' ); // Make sure we have terms and also check for WP_Error object if ( $product_terms && !is_wp_error( $product_terms ) ) { @usort( $...


4

Since it is a performance question, you might be able to avoid using meta keys at all by storing/getting that data another way and not having to set a separate meta field to match with... a. You could get the year from the published $post->post_date... So that when doing the query just use the date argument: $args = array( 'post_type' => $...


3

You can accomplish this with add_rewrite_rule(). I personally like to show this example in a class to make it copy/paste ready. You could throw this in a plugin or functions.php -- some place that loads this code before query_vars, parse_request and init. The goal is to add rewrite rules, make sure you can add custom properties to the main query, then ...


1

Ok, i have some basic ideas. You can install a plugin called Redirection. And after that, you can make like and redirect to some other pages with you own data. but URL will change as the person redirect to the other specific page. Now if you want to them to land on the specific page... you need to make the folder into server directory under the main site ...


0

There is a lot of nuance here, depending on what exactly you want to accomplish. I don't feel confident I completely grasp it from your question. In general WP logic flow is following: URL is converted to query vars query vars go into main query instance main query instance queries posts template loader uses conditional tags (which use main query) to ...


0

It's unclear from your question what the actual problem is; on a hunch, should it be this: if ( ! empty( $entries[ $key ]['newblock_url'] ) ) : ... instead of: if ( get_post_meta( $post->ID, 'newblock_url', true ) ) :


0

Looking at the function source on https://developer.wordpress.org/reference/functions/wp_list_authors/ you can see that the post type of post is hard coded into the sql query that returns the authors and post counts. You could clone the function and add other post types as an argument, but I don't see a more elegant solution sadly.


1

If you're within the loop then the_title() should return the post type's title. post_type_archive_title is specifically for archives. To get the human readable name of the post type, though, I've not seen anything better than this from the Codex: $obj = get_post_type_object( '30-day-boot-camp' ); echo $obj->labels->singular_name;


0

'LIKE' isn't supported by the current version of WP_Tax_Query, so you'll need to write a custom query. This answer from a couple of years ago still seems to be the best approach: http://wordpress.stackexchange.com/a/133805/26317.


0

I don't know what your comments.php looks like, so I cannot tell how to adapt your current code, but I can generally tell you how to approach this. Normally, WP will assume that you want the latest comments of the current post. If you want something else, you start with the condition under which you want your second set of comments to show and add this to ...


0

I eventually managed to find a solution: First of all, the pre_get_posts action that I originally had wasn't good, because both the events and the posts are displayed using the same template (taxonomy-event-category.php). The code that I wrote in pre_get_posts forced wordpress to display only events in that template, so I removed it. I replaced it with ...



Top 50 recent answers are included