New answers tagged

0

@nmr answered the question in the comment.


0

For me, I offer you a solution composed of three parts: 1 - Create a CTP. 2 - Create the necessary javascript and css scripts. 3 - Create a dedicated template in the root of your theme archive-$posttype.php, in our example will be archive-product.php I created a repo in my git where you can download the Plugin here is the link: Custom CPT The source ...


1

I hacked the sh*t out of it. Here is my uggliest solution ever to a simple problem. I am not really happy with this, but it will have to do. For the sake of this example, I will use a custom post type called book and we're gonna validate a field called ISBN. This solution uses PHP Session and header redirect. Here we go... Step 1 - Data Validation The ...


1

I've used jQuery Validate for this sort of thing in a previous project and it worked exactly as I wanted. You have to enqueue the script and then write the validation out but it really did offer me a great deal of control over what was being done. https://jqueryvalidation.org


1

One option could be to use data attributes on the entires listed on pages one and two. Then attach a click event that reads the attribute value on click saves it to localStorage. This way you wouldn't need to make an extra db call on page three. In the loop the data attribute value can come basically from anywhere. E.g. post meta, some post field, taxonomy ...


0

I assume that you're making your custom post type in a plugin if you mean for it to work with any theme. In that case, I would suggest building your templates in your plugin, and call all your meta data there. Example: /* Filter the single_template with our custom function*/ add_filter('single_template', 'my_custom_template'); function my_custom_template(...


4

I'd suggest to not add layout, but MarkUp and offer an option to override it. The best way to do this would be to add to a hook that your users can add to their themes templates. // Theme template file do_action( 'hotel_rooms' ); // Your plugin hooks in there: add_action( 'hotel_rooms', 'callback' ); function callback() { echo "I am displaying details ...


1

On your code, the function wp_get_post_terms() return an array of WP_Term objects, so you can't access directly to an object property without specifying an index for the array like : $terms[0]->slug Otherwise, you should iterate through the whole array of terms and retrieve the slug into an another array, like : $terms = wp_get_post_terms( $post_id, ...


0

You might have forgotten wp_reset_postdata() after the while statement as well: apartquery = new WP_Query($apartargs); if ($apartquery->have_posts()) : while ($apartquery->have_posts()) : $apartquery->the_post(); // Your content endwhile; wp_reset_postdata(); else : // Your ...


1

I think the issue is that it's being interpreted as a STRING type and being ordered character by character. Maybe try turning this into a meta query and forcing the DATETIME type like the example shown below: 'meta_query' => array( 'starttime' => array( 'key' => 'start_time', 'type' => 'DATETIME', ) ), 'orderby' => ...


0

Currently, it looks like you are looping through comments and then querying the posts from there. Could you use the comment_count order by parameter directly in the posts query itself? For example: <?php $post_args = array( 'post_type' => 'portfolio', 'posts_per_page' => 1, 'orderby' => 'comment_count' ); $posts = get_posts($...


0

Depending on the hierarchy of WordPress templates, you can create a template: category-$slug.php, in your case, it will be: category-destinations.php (to mention that the slug must be the same name) . So this template will have the priority if we click on the link category destinations. I used Twenty Nineteen theme. Templete named : category-...


0

Change $loop = new WP_Query( array( 'post_type' => 'portfolio', 'posts_per_page' => -1 ) ); to e.g. $loop = new WP_Query( array( 'post_type' => 'portfolio', 'posts_per_page' => 9 ) ); If you set posts_per_page to -1 you will always pull all available posts. Hence, no pagination will show up since all posts are already shown on the first page.


0

I would definitely recommend the Custom Post Type route. You will have two issues: How to automatically add new properties when the XML is updated. How to update existing property values if they change (e.g., House A has a price increase after the initial import). To solve the first, you can set up a WordPress cron that will hook into your import action....


-1

This works for me. I have done it only for anco_project_year_from but you can easily add the condition for anco_project_year_to. Hope it helps. function anco_project_year_column_orderby( $query ) { if( ! is_admin() ) { return; } $orderby = $query->get( 'orderby'); if ( 'anco_project_year_from' == $orderby ) { $query->...


0

In the WP Docs you can find the answer. I have not tested this snippet, but it should become something like this: $args = array( 'post_type' => 'product', 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'product-ean', 'value' => 123, 'compare' => '=', ...


0

In the past I have made it with https://developer.wordpress.org/reference/functions/add_rewrite_rule/ The best solution, with a simple regexp can read and detect all parameters in your URL and rewrite to show the correct post


0

You can find here the solution: https://developer.wordpress.org/themes/basics/template-hierarchy/#category Rendering category archive index pages uses the following path in WordPress: category-{slug}.php – If the category’s slug is news, WordPress will look for category-news.php. category-{id}.php – If the category’s ID is 6, WordPress will look ...


0

I found this plugin that made my life easier, so I didn't have to code all that https://wordpress.org/plugins/wp-rest-filter/


0

I think using the pre_get_posts action should do the trick. Something along these lines. Modify as needed. Add to functions.php. function my_limit_admin_posts($query){ if ( is_admin() && $query->is_main_query() && 'your_post_type' === $query->get('post_type') && current_user_can('some_capability_or_role') ) { $query->...


0

For players you could create a custom post type, like so function my_player_cpt() { $labels = array( 'name' => _x( 'Players', 'Post type general name', 'textdomain' ), 'singular_name' => _x( 'Player', 'Post type singular name', 'textdomain' ), ); $args = array( 'labels' => $labels, '...


0

This worked for me. 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'colors', 'compare' => 'NOT EXISTS' // doesn't work ), array( 'key' => 'colors', 'value' => 'blue' ) )


0

You can use meta_query property when fetching post data using new WP_Query() $vehicles = new WP_Query([ 'post_type' => 'vehicle', 'meta_query' => [ 'relation' => 'AND', [ 'key' => 'wheel', 'value' => '4', ], [ 'key' => 'color', 'value' => 'blue',...


0

You can use post__not_in with the get_the_ID of the post in this case your code should be like this : $args = array( 'post_type' => 'custom_post_type', 'tax_query' => array( array( 'taxonomy' => '...


1

Thanks! We ran into the same issue and this question helped a lot! Alternate Use Case We're looping through a custom post type called events (surprise, surprise, it stores events). It stores a timestamp in the meta field ev_start (event start time). We actually were able to just use the orderby value meta_value_num (as you can see meta_type is commented out)...


1

It depends on how you added the custom fields. If you used a custom fields plugin, you may be able to call a plugin-specific function. For example, with ACF, you can call get_field('fieldname') to retrieve one specific custom field. If you're not using ACF (or even if you are), as long as your fields are stored as postmeta, you can do something like <?...


-1

In my case it was missing rights in my development folder so .htaccess file could not have been created ad/or modified. So manual flushing or Saving changes in WP Permalinks was not helping. Solution was to create .htaccess file by myself


0

Modify your code as below: /********************************************** * Add featured video to REST API ***********************************************/ function add_featured_video_id() { register_rest_field( array('post', 'project'), 'featured_video_id', array( 'get_callback' => 'get_featured_video_id', '...


0

An alternative, but similar solution to Stefan and Rafa's. This does not throw errors, and notice if you navigate directly to /wp-admin/edit.php you will not be able to view the list of posts (default post type), or edit them. Note this code does not actually disable the default post type, i.e. existing post types will still be published and accessible via ...


0

so I added if( is_main_site()) { $slug = 'uniquename'; } else { $slug = 'uniquenametwo'; } and 'rewrite' => array('slug' => $slug ), inside register_post_type function and it worked. before i tried outside it. Im new to this. Anyway this worked in my case.


1

You might have already figured this out, but here's an example how to get custom taxonomy terms for a post and create a list of links for the found terms. // used in your custom post type template, e.g. single-movies.php $genres = get_the_terms( get_the_ID(), 'genres' ); // current post has genre terms attached to it if ( $genres && ! is_wp_error( $...


0

At the beginning I will indicate that the expected structure conflicts with the default for custom post type produce posts. The solution to the problem requires changing the links created for the custom categories and appropriate parsing of new links to display the right posts. Use the pre_term_link filter to change links. One of the parameters passed ...


0

I just allowed all users to show in the 'Author' selection: add_filter( 'wp_dropdown_users_args', 'add_subscribers_to_dropdown', 10, 2 ); function add_subscribers_to_dropdown( $query_args, $r ) { $query_args['who'] = ''; return $query_args; }


0

Try to rewrite the taxonomy url in the .htaccess RewriteRule ^produce_category(.*)$ /$1 [L] (Not tested)


0

Ok so I've found what I was looking for. https://www.advancedcustomfields.com ACF solved the problem. I can only recommend.


-1

if you are not using Gutenberg in article CPT you can easily solve this problem in 5min using PIKLIST plugin. On the other hand u can also fix it by creating custom meta box where your Writer list will shown as Html Select field. Let me know if you need any further help.


1

save_post and new_to_publish is enough, with some checks, to update post metadata. And you don't need the redirection. <?php /** * Update Postmeta. * * @param integer $post_id Post ID. */ function wpse355298_job_publish_status( $post_id ) { // Check autosave. if ( wp_is_post_autosave( $post_id ) ) { return $post_id; } // ...


0

I've managed to figure out what's causing this error. For some reason, 'taxonomies' is looking for an array, even if I only have one taxonomy I'm relating it to. Changing the 'taxonomies' value like so resolved the PHP error: 'taxonomies' => array( 'rich_review_tax' ),


0

I don't know if it'll help but try putting the supported functions into their own variable array like you do with labels. $supports = array( 'title', 'editor' ); Then, under $args, use 'supports' => $supports. I use that for 'labels', 'supports' and 'taxonomies'. Should also note that it's good practice to make your variables a bit more ...


0

Try this: foreach ( $donation_group_posts as $dg_post ) { $dg_id = $dg_post->ID; if(have_rows('YOUR_REPEATER_SLUG', $dg_id)){ while(have_rows('YOUR_REPEATER_SLUG', $dg_id)) : the_row(); echo get_sub_field('YOUR_FIELD_SLUG'); endwhile; } }


1

It looks like your query is for ALL posts in that post type as you are overwriting $posts when using $posts = get_posts(). You need to pass the Taxonomy parameter correctly as explained here like this: $args = array( 'post_type' => 'post', 'tax_query' => array( array( 'taxonomy' => 'people', 'field' => '...


0

In your second file Car_Data_Meta_Boxes_Init line: add_action( 'save_car_data_meta', array( $this, 'save_meta_boxes' ), 10, 1 ); you bind to your custom action save_car_data_meta but this action is triggered inside save_meta_boxes function this is why it never gets triggered unless you do var_dump(Car_Data_Meta_Box_Data::save_car_data_meta(158)); manual ...


0

You can try with below condition for shop page only. if ( $product->is_type( 'variable' ) && is_shop()) {


1

I realize you've already answered your issue. However, I think there is some additional explanation possible to give more clarity to the issue and the solution. The issue is your lqdnotes_add_div() function. This is hooked to a filter - the_content. In WordPress, any time you use a filter, your filter function must return a value for the item being ...


0

StackOverflow may be my rubber duck. Almost immediately after publishing the question the solution popped into my mind. The problem was in the function lqdnotes_add_div. This function took $content (the post content) as a parameter. If post was not of type lqdnotes then it didn't perform any operation on $content...or so I thought. PHP actually returns ...


Top 50 recent answers are included