Tag Info

New answers tagged

1

Are you sure that you don't have a page with the same name of the custom post type? If you do, the permalink rewrite rules will get confused and trigger a 404. A very simple solution is: The page that lists the custom post types is called in plural (eg. products) and the actual post type name is in singular (eg. product). So they don't conflict and it's ...


1

The context of your code that fails isn't entirely clear, but it's failing because get_the_ID() won't return a post ID when run on the init hook, because the main query hasn't been executed yet. If you have a look at the Action Reference, wp is the earliest action where you can access the current query's data, if your code is operating on the currently ...


1

Hook your form processing code to an action that runs before the page is rendered and no redirect will be necessary. function wpd_check_submission(){ if( isset( $_POST['start'] ) ) { // do your post insertion here } } add_action( 'init', 'wpd_check_submission' );


1

I searched everywhere in post type registration flow but didn't found a right way (using filter or action) to do it. All you can do either register the post type again with a different slug (I prefer) or just run those lines of code which WordPress run to build the rewrite rules in register_post_type. I register this post type with slug book and changed it ...


0

I would recommend using the php core function money_format() the code should look something like this: $meta = get_post_custom($post->ID); // value=123456 setlocale(LC_MONETARY, 'en_US'); echo money_format('%i', $meta) . "\n"; // USD 1,234.56 Cheers


0

OK, thank you to ialocin, the $gbquery->max_num_pages solve it! So there is the clean code : function livredor_function($atts,$content=''){ extract(shortcode_atts(array( id => '' ), $atts)); ob_start(); function create_guestbook() { $current_page = (get_query_var('paged')) ? get_query_var('paged') : 0; ...


0

Legacy reasons. At the beginning WP only had posts. No. There are uncountable other things connected. You can query for it separately, have other permissions, different backend UI and much more. Finding the right template might be one thing, but then again it doesn't have to be as the template hierarchy can be modified in many ways. No. It would look like ...


0

I had this same problem when I cloned my site to set up a development server - for me, it working by setting permalinks to ugly, saving, then setting them to pretty again, which rebuilt whatever had gone wrong in htaccess.


3

You can set the expire date as post meta value. In single.php you can easily show that date by querying the post meta. See update_post_meta() and get_post_meta() Now, the second part of your question is pretty tricky. I can think of 2 solutions. Cron You can use wordpress cron to run at a time interval to check which post has been expired and ...


0

The name you are using for taxonomy isn't allowed. register_post_type() $taxonomy parameter says $taxonomy (string) (required) The name of the taxonomy. Name should only contain lowercase letters and the underscore character, and not be more than 32 characters long (database structure restriction). Default: None So, you need to change the ...


3

Are you calling flush_rewrite_rules at any moment? If you are going to change the slug of a custom post type, you also have to call the flush_rewrite_rules. You can find more documentation here Setting up custom post type archives in WP3.1? Any luck? And here https://codex.wordpress.org/Function_Reference/flush_rewrite_rules


0

The problem was with exclude_from_search parameter when I registered the post type. exclude_from_search (boolean) (importance) Whether to exclude posts with this post type from front end search results. Default: value of the opposite of public argument 'true' - site/?s=search-term will not include posts of this post type. 'false' - ...


0

You should follow appropriate naming convention (aka Template Hierarchy) of your templates to make your job done. If I'm clear about your query here then I'd suggest you to name your custom taxonomy archive template(s) as "taxonomy-{your-taxonomy-name-here}.php" (i.e. taxonomy-vegetable.php, taxonomy-fruit.php and so on) There must not be any blank ...


0

You can try something like this $titels = ""; $content = ""; $html = ""; $counter = 1; while ( $custom_query->have_posts() ) : custom_query->the_post(); if ( counter % 5 = 0 ) : $html = "<div class='row'>" . $titels . $content . "</div>"; $titels = ""; $content = ""; endif; $titels .= "<div>". ...


0

Have you tried using rewind_posts()? It looks to me like what you'll have to do is either run the entire query only outputting titles then rewind and output content (however this would output all titles before the content, not in blocks of 5 as you have suggested) or wrap everything in a loop which runs the same query limited to 5 posts each time, then ...


0

Yep! After a lot of research I got plugin 'Custom Permalinks'. Which fulfils my requirement regards - custom URL e.g. for Category for Post for Custom Post for Custom Taxonomy etc. Like this Custom Post Type - Post:


0

iolocin, I took your edited answer and as Pieter Goosen mentioned, made sure it was an array in an array and as per the codex. Final working code: function wpse188669_pre_get_posts( $query ) { if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) { $tax_query = array( ...


0

There is the hook manage_${post_type}_posts_columns which can be used to do just that. Basic example: function wpse188743_events_cpt_columns( $columns ) { $new_columns = array( 'event_date' => __( 'Event Date', 'textdomain' ), ); return array_merge( $columns, $new_columns ); } add_filter( 'manage_events_posts_columns' , ...


0

If you are not using multiple key & values, I'd try it this way // This function adds a meta box with a callback function of my_metabox_callback() function add_my_meta_box() { $var1 = 'this'; $var2 = 'that'; add_meta_box( 'metabox_id', 'Metabox Title', 'my_metabox_callback', 'page', ...


2

The following filter shows only the top-level custom post type items in page attribute dropdowns (in main edit screen and in quick edit). Replace the 'my_custom_post_type' with your custom post type name. function my_test($args) { global $post_type_object; if ( $post_type_object->name == 'my_custom_post_type') { $args['depth'] = 1; } ...


0

After hacking around, this is the solution I came up with: At the top of functions.php I have the following line: add_action('admin_footer', 'add_title_to_editor'); Just thrown in the middle of functions.php I have the following function: function add_title_to_editor() { global $post; if (get_post_type($post) == 'my_custom_post_type') : ?> ...


1

i'm not exactly sure the full context of what you are doing here. there are a number of possible solutions. first is to make sure you are accessing $post as you expect. in other words, make sure it is not being affected by other activity as WordPress builds the page. i don't know if $post contains the object you expect at this point in the flow -- because ...


3

The problem with your approach is that woocommerces product category is a custom taxonomy called product_cat. But with cat you are addressing the built-in category. Taxonomies can be addressed with a tax query, simplified example below: function wpse188669_pre_get_posts( $query ) { if ( ! is_admin() && ...


0

So to answear my own question after much googeling: In the args array I commented out the option for show_in_menu, so that custom post type creates the menu itself. Then I didn't add the admin menu, but just the submenu (the hook still remains). add_action('admin_menu','bsp_plugin_menu'); And the first parameter is the one that shows it in the menu ...


1

I would just just scrap the function above as there are several bugs in the code and is also not quite effecient. I am actually surpriced that it really works for you. Your best solution here would be to write a complete new function. Here is want we want to do and how we are going to accomplish this Get the current post object on the single post page. ...


0

So to achieve your 2 issues all we have to do is modify the $args array that is being used for the Query. Because this is a Query we can use any of the parameters that Wordpress has kindly provided for us here: WP_Query. Like this one: post__not_in (array) - use post ids. Specify post NOT to retrieve. And this one: posts_per_page (int) - number of post to ...


0

Ok, after a little playtime, here is the answer: add_action('save_post', 'ocp_jobs_save_details'); function ocp_jobs_save_details(){ global $post; $genref = sanitize_title( dechex( time() ) ); if ( $post->post_type == 'job' ) { if ( $_POST['ocp_jobs_ref'] ) { $jobs_args = array( 'ID' => $post->ID, 'post_name' => strtolower( ...


1

I recently used this in one of the projects, so here you go add_action( 'edit_form_after_title', 'wp692_edit_form_after_title' ); function wp692_edit_form_after_title() { echo '<h2>This is My Label!</h2>'; }


0

Solved it just by using taxonomy-{taxonomy-name} in an array in the filter manage_{post-type}_posts_columns


1

Here's the code, rewriten from posts and categories to custom post types and taxonomy terms. Thanks to @PieterGoosen for providing the first version. http://pastebin.com/xKBepGQz <?php $args = array( 'post_type' => 'produkty', // your CTP name 'meta_key' => 'produkt_nowosc', // custom meta key for displaying, in my case: the newest ...


0

I can't comment yet, but I would suggest first to modify your loop <?php // The Query $query = new WP_Query( $args ); // The Loop <?php if ( $query->have_posts() ) : ?> <?php while( $query->have_posts() ) : $query->the_post(); ?> <li><?php the_title(); ?> - <?php get_post_meta( get_the_ID() , ...


1

Use the map_meta_cap filter to conditionally prevent users who cannot manage_options (i.e. administrators) from editing/deleting certain posts: function wpse_188368_map_meta_cap( $caps, $cap, $user_ID, $args ) { if ( in_array( $cap, array( 'delete_post', 'edit_post' ) ) && $args && ! current_user_can( 'manage_options' ) /** Only proceed ...


1

Your tax query should be an array of arrays. Important Note: tax_query takes an array of tax query arguments arrays (it takes an array of arrays). This construct allows you to query multiple taxonomies by using the relation parameter in the first (outer) array to describe the boolean relationship between the taxonomy arrays. ...


0

I realize this is an old question, but I recently needed to do just this. My solution was to hook into wp_head and run any shortcodes in the post content. This works because the shortcodes I'm dealing with call wp_enqueue_script and wp_enqueue_style when they are processed. The code looks something like this: function example_shortcodes() { global ...


0

WordPress generates an archive page when your register the CPT. As stated you can modify posts per page from your functions file and register both the CPT and Taxonomy support using this code: add_action( 'pre_get_posts', 'set_items' ); function set_items( $query ) { if( $query->is_main_query() && !is_admin() && is_post_type_archive( ...


0

The following code works for WordPress >= 3.5 (source). I couldn't get it to work the ACF way. No need to use 'meta_query' this way. Just replace 'meta_query' with the following two lines to offer_args and and it should work. 'meta_key' => 'home_offer', 'meta_compare' => 'EXISTS', // or 'NOT EXISTS' if no offer.


0

It is simple: If $post is not a revision, wp_is_post_revision() returns false; just reading the name of the function give you the reason. wp_is_post_revision() returns the parent post ID only if the given post is a revision (a revision has always a parent post). It seems that you want to get the parent post ID of $post, not checking if $post is a revision. ...


0

If you used people and location as custom taxonomies, you'd be able to build them into a new WP Query instead. In fact, depending on how you're storing your custom fields, you might be able to do it through WP Query without going down the custom taxonomy route. Then, you don't need to post request anything - the query handles everything.


0

Tried with this and got the solution add_submenu_page( 'page_main', "Articles", "Articles" , 'adminstrator', 'edit.php?post_type=page_article' ); Thanks


1

I'm not sure if I undestand you correctly, but maybe this will help you. If you're on CPT archive, then there is no "Edit" link, because it's archive and not a page... Archive is list of posts, so there is no single post to edit... Another example of archive page is when you're viewing search results or all posts from given year - there is nothing to edit ...


1

The filter wp_title won't pass $id to your function. Drop the parameter and instead retrieve it with get_queried_object_id(): function dw_listing_title( $title ) { if ( is_singular() && $id = get_queried_object_id() ) { // Modify $title as required } return $title; }


0

answer ^^ add_action( 'load-edit.php', function() { global $typenow; // Not our post type, bail out if( 'community' !== $typenow ) return; // Administrator users don't need this, bail out if( current_user_can('add_users') ) return; // Only the Mine tab fills this conditions, redirect if( !isset( $_GET['post_status'] ) && !isset( ...


0

If using css: #edit-slug-box { display: none; }


0

Try this way: add_action( 'save_post', 'myFunc'); function myFunc(){ if ($post->post_type == 'cpt' ) { // do action here } OR add_action( 'save_post', 'myFunc'); function myFunc(){ if ( 'cpt' == get_post_type() ) { // do action here }


0

As @Pieter said, you can use transition_post_status: function wpse_187997_job_status( $new_status, $old_status, $post ) { if ( $post->post_type === 'job' && $new_status !== $old_status ) { // Post type "job" and status has changed } } add_action( 'transition_post_status', 'wpse_187997_job_status', 10, 3 );


0

I know the feeling. I constantly have this battle between an archive slug and a static page called the same thing. i.e. Portfolio CPT archive and www.yoursite.com/portfolio page with editable content. I have two ways to accomplish this, both fairly hacky (which I hate): Create archive-{portfolio_cpt}.php archive template and include a static page template ...


1

I have some recommendations for your question: First: stop using query_posts(). See the codex about this function to see why you shouldn't use it in themes or plugins. Anyway, if you are in a some weird situation where you have not option and you need to use query_posts(), you should run wp_reset_query() after the loop. You must know that you are using the ...


0

I figured out the answer, since I am registering my taxonomy as phototype I simply have to create a file named taxonomy-phototype.php and inside that I will get the data by looping like I normally would in wordpress <?php if (have_posts()): ?> <?php while (have_posts()) : the_post(); ?> <?php the_content(); ?> <?php ...


0

I have had similar mysterious behaviour with CPTs and pretty permalinks. Try to regenerate your permalinks by switching to another structure and back again. Or check out flush_rewrite_rules() in the codex. https://codex.wordpress.org/Function_Reference/flush_rewrite_rules


0

You have to run the loop , modify your search.php something similar to the code below <?php get_header();?> <div class="wapper"> <div class="contentarea clearfix"> <div class="content"> <ul> <?php if ( have_posts() ) : ?> <header class="page-header"> ...



Top 50 recent answers are included