New answers tagged

0

save_post didn't work for me. What works in my situation is using content_save_pre filter or the content processing before save. Since I'm using Advanced Custom Field plugin for my cover_image field, and I ended up using acf/save_post filter to process the field.


2

The admin-init hook only fires on admin screens. The correct hook to use for registering post types is init. So change: add_action( 'admin_init', 'smoelenboek' ); ... to ... add_action( 'init', 'smoelenboek' ); ... and flush your rewrite rules once (save permalink settings in admin) and all should be well.


0

While I agree with @cybmeta that it sounds like an edge case considering WP, it's a reasonable requirement. And we throw out questions that are too general :-) I'm sidestepping your exact question a little, as I can see that creating a number of posts and forcing their slugs to be non-unique might be a recipe for future disaster. What do you do to the ...


0

Please go through serialize array concept in wp.In your postmeta it is storing data in serialised form if you are getting an array. Either you can loop through the array or to fetch a single record use the array key.


1

You got ARRAY echos because you saved array on post meta, Just check array values of meta data like: print_r( get_post_meta($post->ID, 'ptn_systeem', true) ); and echo it like: foreach( (array) get_post_meta($post->ID, 'ptn_systeem', true) as $option): echo $option . "<br>"; endforeach;


1

image_send_to_editor hook will handle when the image is sent to the editor. The problem will be that your editor may not work correctly when you modify the URL -- use with caution. save_post will allow you to modify the $post content on save. update_(meta_type)_metadata could be used to intercept when the meta data is saved.


0

As per what I have understood is you have a Custom Post type as event and user role like Secretary. Now if a Secretary logged in , he can only be able to see his own events added, not the other one. So if the above is correct so for that, we will use pre_get_posts filter function wp_list_mine_posts( $wp_query_obj ) { // Front end, do nothing if( !...


1

First off, it's always good to register shortcode during init versus just in your general functions.php file. At the very least add_shortcode() should be in init. Anyway, let's begin! Whenever you use add_shortcode() the first parameter is going to be the name of the shortcode and the 2nd will be the callback function. This means that: [products line="...


2

First, you need to declare/register the new columns: add_filter( 'manage_tour_posts_columns', 'cyb_add_new_columns' ); function cyb_add_new_columns() { $columns['price'] = __('Price column title', 'cyb-textdomain' ); $columns['test'] = __('Test column title', 'cyb-textdomain' ); return $columns; } Then, you can print the content ...


-1

<?php $args = array( 'post_type' => 'product', /* your Custom post slag */ 'meta_key' => '_wla_homepage_slider_checkbox', 'meta_value' => 'on', 'posts_per_page' => 15, 'no_found_rows' => true ); $query= new WP_Query( $args ); ?>


0

When you want to output trusted html, use html_entity_decode. $orig = "I'll \"walk\" the <b>dog</b> now"; $a = htmlentities($orig); $b = html_entity_decode($a); echo $a; // I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now echo $b; // I'll "walk" the <b>dog</b> now You can find more examples here.


0

Use the 'show_in_menu' argument of register_post_type() to specify the URL path of the parent menu item. For example, a value of 'edit.php' will nest the CPT's management pages in the Posts menu item, 'edit.php?post_type=page' will nest them in the Pages menu item, and a value of 'users.php' will nest them in the Users menu item.


0

This is just a modification of timshutes' answer - if you want specific pages to require login and don't want to put them into a custom post type, you can add to functions.php: add_shortcode('need_login', 'shortcode_needLogin'); function shortcode_needLogin() { if (!is_user_logged_in()) { auth_redirect(); } } And then at the top of the ...


1

Setting theme dynamically is certainly possible, but not too convenient since it's hardly "normal" mode of operation. In my experience this works best if you stay away from higher level template/stylesheet hooks and instead filter underlying options. In that way you can trick WP into thinking that configured theme is different from what it is and use it. ...


0

Unfortunately the hooks: manage_{$this->screen->id}_columns manage_{$this->screen->id}_sortable_columns manage_comments_custom_column are not available for the post-comments list table, constructed within the wp_ajax_get-comments call. That table consists only of two columns: author and comment. The data for author, avatar, email, url and IP ...


0

Here are some thoughts : the_post_thumbnail() already echo so you cannot echo again you could use echo get_the_post_thumbnail() instead But in your case I don't really see why you use get_posts() most of the time we use it to get post data and make other treatments. You'd better use your own instance of WP_Query here like this : <?php $_posts ...


0

Custom post type can have template options like Pages, but its little complex, but i will try to explain it: 1) you need to register a new meta box with a drop down (custom meta field) of all the templates: function register_post_cookingrecipes() { add_meta_box('cookingrecipes-details', __('Template Details'), 'add_cookingrecipes_meta_box', '...


0

It's a bad use of Query you may look at this post In this case use a secondary query with your own instance of WP Query. query_posts() is not recommanded here cause it overrides the main query. <?php $args = array( 'post_type' => 'instrument', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, ); $my_query = ...


0

For comment approved, you can review this question Approve comment hook? For comment submitted, you can hook into the comment_post hook, like function show_message_function( $comment_ID, $comment_approved ) { if( 0 === $comment_approved ){ //function logic goes here } } add_action( 'comment_post', 'show_message_function', 10, 2 ); Code ...


0

Insert Data in Custom Post From Front End if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "product") { $title = $_POST['title']; $post_type = 'product'; //the array of arguements to be inserted with wp_insert_post $front_post = array( 'post_title' => $title, '...


0

Try This Custom Code For Create Post From Front End Insert Data in Custom Post From Front End if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "product") { $title = $_POST['title']; $post_type = 'product'; //the array of arguements to be inserted with wp_insert_post $...


0

Create Custom Post Type function create_product() { $labels = array( 'name' => _x( 'Product', 'post type general name', 'stacy' ), 'singular_name' => _x( 'product', 'post type singular name', 'stacy' ), 'menu_name' => _x( 'Products', 'admin menu', 'stacy' ), 'name_admin_bar' => _x( 'Product', '...


0

Create Custom Post Type Create post type page $page = get_page_by_path('buyer-order-request'); if (!$page) { $buyer_order_requ= '[buyer_order_request]'; $post = array( 'comment_status' => 'closed', 'ping_status' => 'closed' , 'post_author' => 1, 'post_content' => $buyer_order_requ, '...


0

Ok as mmm has pointed out that I can't do the dropdown select of templates on custom post types I have put this code in my single-cpt.php global $post; if ( ( $post->post_type == 'location' ) && has_term( 'news', 'highlights' ) ) { include('templates/template_feature_highlight_layout.php'); }


1

This is a little old but you can also try this: Create a template for the custom post type: single-*custom-post-type-slug*.php The file should check the slug and verify if a file exists, if not, fallback to a default template file: <?php $slug = get_post_field( 'post_name', get_post() ); $slug = ( locate_template( 'templates/*custom-post-...


0

You need to do this when you register your taxonomy in register_taxonomy() Pass the rewrite argument and customize to your needs: 'rewrite' => array('slug' => 'groceries/fruit', 'with_front' => false) You'll probably need to flush your permalinks in Settings as well.


0

I figured it out. Thanks to an answer posted here. The code is $term_slug = get_query_var( 'term' ); $query_args = array( 'taxonomy' => 'news_category', 'term' => $term_slug, 'post_type' => 'news' );


0

You can use this code to make the parent post type active in the menu: <?php add_action('nav_menu_css_class', 'add_current_nav_class', 10, 2 ); function add_current_nav_class($classes, $item) { // Getting the current post details global $post; // Getting the post type of the current post $current_post_type = get_post_type_object(...


2

As of WordPress 4.5 there is function to do that, unregister_post_type. Example:- function delete_post_type(){ unregister_post_type( 'blocks' ); } add_action('init','delete_post_type');


1

Good news - there's nothing you need to do. WordPress does this for you out of the box, providing you have set up your post type and taxonomy to do so. You should be able to access your posts at http://example.com/labels/events, once you've checked: that your post type is publicly_queryable (either the public argument or publicly_queryable argument is set ...


3

You can filter the posts list by appending ?category_name=xx to the admin posts list URL, and you can add a submenu page with that URL as the target via add_submenu_page: add_action( 'admin_menu', 'wpd_admin_menu_item' ); function wpd_admin_menu_item(){ add_submenu_page( 'edit.php', 'Page title', 'Menu item title', '...


0

You can loop posts by category name or ID: $query = new WP_Query( array( 'category_name' => 'staff' ) ); or $query = new WP_Query( array( 'cat' => 4 ) ); and just use good old fashion way to loop: if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); get_title(); endwhile; else : echo 'No ...


1

Remove return; from your code, which is prematurely exiting the function before the following two lines can be executed; that is why the status is not changed. function my_change_status_function () { global $post; $ordernumber = get_post_meta( $post->ID, 'order_number', true ); $audit_status = get_post_meta( $post->ID, 'audit_status', ...


0

You've got the slug of the term in the query string, so you can use the get_term_by() function to get the term object. For example, assuming your taxonomy name is 'dir-type': $country = get_term_by( 'slug', $_GET['country'], 'dir-type' ); Using that, you can then print out information from the term object like this: echo $country->name; // print the ...


0

Try to get the value of querystring $country = $_GET['country'];


0

Working from of Sven's really good answer, I rewrote his function to make it easier to add multiple post types using in_array() in the if statement and then redirecting to the archive page instead of the home page. (by the way, I think the setting query_var and/or publically_queryable to false will disable not only the single views, but also the native ...


0

in the action request, the keys meta_key and orderby already exists then try to overwrite like this : if ( isset( $vars['orderby'] ) && 'count' == $vars['orderby'] ) { $vars["meta_key"] = "count"; $vars["orderby"] = "meta_value_num"; }


1

I don't know why your $_POST data disappears. However, consider using the admin_post/admin_post_nopriv hook to process the form data using a function on the back end. That's what the function was made for. At the end of the function, you can then redirect to the account-pending page using this wp_redirect(home_url('/account-pending')) .


0

The single_template filter will let you use whatever template file you want for your CPT, but it's up to you to provide some means of selection and storage of a template name or some other reference to make it a dynamic solution. The built-in page post type does this by reading all of the valid template files in your theme, and adding that list to a meta ...


1

From what I understand, you've got two options. Option 1: Dynamic Solution Create categories for your custom post type - each category is going to have its own template. You then create a single template that splits off based on category. Meaning you use the general header and footer in your single-postypename.php and anything else that you want to apply ...


0

First, you don't need the <form> tags; meta boxes are already rendered inside the post edit form. Second, if a checkbox is not checked it is not sent, so isset( $_POST['checkbox_name'] ) return false and the custom field that stores the value of the checkbox is not update correctly. I've tested this code with standard post type and it works, it must ...


0

A slightly different version than Stephen's. I integrated some things and changed others. Code is tested and works fine, as I'm using it in a project. function add_calendar_feed(){ add_feed('calendar', 'export_events'); // Only uncomment these 2 lines the first time /*global $wp_rewrite; $wp_rewrite->flush_rules( false );*/ } add_action('...


0

You could consider using the page templates. For the example im going to use a contact page. "contact-page.php" You can then write in the code you need for the template. To keep the flexibility look up how to use the Customizer (if you're not familiar with it) and use this in the template page to let the admin modify the page content without having to look ...


0

While shortcodes by themselves are linked to functions, I think you could use them effectively in combination with templates and a metabox for their input data. eg: add_shortcode('content-box','content_box_function'); function content_box_function() { global $post; $title = get_post_meta($post->ID,'_content_box_title',true); $content = ...


1

Assuming your custom post type is named "job_posting", you just need to change your query to read: $query = new WP_Query( array( 'post_type' => 'job_posting' ) ); This can be found in the official documentation. There's a lot more parameters you might like to use too - you can find a full list in the documentation I linked to. Some I'd recommend ...


1

Ok, so I found the solution to this problem and I thought I'd post it here for anyone else who may stumble upon this question. Turns out I was making this much more difficult than it needed to be. I just added a simple function to the custom site plugin I created (this could also be added to your functions.php file). function hea_cpt_author( $query ) { ...


2

This is an interesting question, though a bit too broad for a Q&A model. Here is what I would do: Create a custom post type, where each post is a block of content Create a second custom post type for pages that are assembled from blocks of code. In stead of a content field, create ten drop down fields (or more if there are more blocks possible on a ...


0

http://src.wordpress-develop.dev/category/Markup/ or another link is not a post type archive page, it is a archive page. archive page is not a post type archive page. archive page access link like above, but post type archive page access link like: http://src.wordpress-develop.dev/(post-type) replace the (post-type) with the really post type. There is no ...


2

When 'is_post_type_archive()' return true? is_post_type_archive() returns true for custom post type archives and false for default posts. Use is_archive() to check for default posts.


0

Here is the solution folks. I've commented on each line to clarify what's going on. Hopefully, it all makes sense and is correct :) I appreciate the help I received from this rockstar community. <?php // Let's get the data we need to loop through below $args = array( 'post_type' => 'carillon', // Tell WordPress which post ...



Top 50 recent answers are included