Tag Info

New answers tagged

0

I recommend not reinventing the wheel and looking at Reusable-Custom-WordPress-Meta-Boxes Even though this code is no longer supported it's concise enough to be easily manageable. I use it and it works well. All you need to do is add the meta_box.php file to your functions.php and from then on use the predefined components: ...


0

I was able to resolve this problem. It would appear that the 'save_post' action occurs prior to the init that is registering the custom post type. Therefore, the post type's rewrite slug is not updated prior to the request to flush_rewrite_rules, essentially resulting in no update. This also explains why it works if the post is saved a second time, since the ...


1

I am not sure without running which query precisely this results in, but I don't think it is intended format for such query. If you take a look at Date Parameters documentation, there is a special case of after and before when you want to find posts in some direction from specific point.


0

Try to put return $types outside foreach loop.


1

You could just echo do_shortcode( $content ); Function Reference/do shortcode


0

Here's something that should kinda work... in spite of the fact that CPTs don't have a parent category as regular WP posts do. function get_cpt_parent_cat_aka_taxonomy() { global $post; $parent_tax_name = 'Undefined parent taxonomy!'; $obj_taxonomies = get_object_taxonomies( $post->post_type, 'objects' ); $slugs = array(); if( !empty( ...


0

I used: $args = array( ... 'rewrite' => array( 'slug' => 'portfolio-taxonomies' ), ... ); register_taxonomy( 'portfolio_taxonomies', array('portfolio'), $args ); So my URL is predictable. And you did one thing wrong, URL you are putting is NOT correct. If the rewrite rule is implemented, then they would be: ...


0

Try this: function options_instructions_example() { global $my_admin_page; $screen = get_current_screen(); if ( is_admin() && ($screen->id == 'custom_post_type_name') ) { function add_content_after_editor() { global $post; $id = $post->ID; echo '<div class="postbox" ...


0

After some offline conversations with other developers, I came to the solution of creating a settings page under any given custom post type menu. A quick way to get up and running is by using Advanced Custom Fields and this handy snippet by Jared Atchison.


0

Thanks for your help. What I want exactly is like the image bellow. I need a text box that user can type key word and they also can filter by select the drop-down. In drop-down, it has custom field like Publication Year, Author...


0

For those coming here because of the title of the question: If you have a look at Post Formats at the Codex you'll see that [...] New formats cannot be introduced by themes or even plugins. [...] Which kills you're option 2. Also have a look at this: Custom Post Formats For your apparent actual question: It really depends on how much they differ. ...


0

I would do as @cfx suggested: register_taxonomy( // Call before register_post_type() to give rewrite rule priority. 'bike_category', // Should be singular, not bikes_category 'bike', array( 'rewrite' => array( 'with_front' => false, // This will strip the "blog" prefix 'slug' => 'bikes', ), ...


1

And to create a custom post type is not an option? 'post_type' => 'custom_post_type' then just hide the custom post type from the UI see Possible to hide Custom Post Type UI/Menu from specific User Roles?


0

Edit: I thought this would be fairly simple but seems I'm just not competent enough. You could get around it by adding an arbitrary category (like my_prog_cat_to_hide) for these programmatically added posts and then filtering them out in the admin listing. function wpse182434_get_category_id($cat_name){ $term = get_term_by('name', $cat_name, ...


0

You can do this with a built in WordPress query property $the_query->current_post (first post will be 0) without the need to setup a counter: <?php get_header(); ?> <?php $args = array( 'post_type' => 'question', 'order' => 'ASC' ); $the_query = new WP_Query( $args ); ?> <div class="wrap"> ...


0

There are many options, but these functions are your friends: wp_insert_post - pass it some arguments and it will create a post and if succesful, return the post ID wp_set_object_terms - pass it a post ID, a custom taxonomy, and the terms you'd like to set fopen - for opening a csv file fgetcsv - reads in a single line from a csv and returns it for ...


0

You should really re-title this question and refine your question further. From what I gather you are actually trying to find out how to add posts to your custom post type that has custom fields via a CSV. My suggestion is to look for a plugin that imports posts from a CSV and either find one that already has a column for post_type and columns for custom ...


0

Using pre_get_posts may work. Can you try something similar to the following and let me know if it meets your needs: function search_filter($query) { if ( !is_admin() && $query->is_main_query() ) { if ($query->is_search) { $query->set('post_type', array( 'post', 'movie' ) ); //Should do some sanitation on $GET too ...


0

Thank you @TomJNowell, I didn't end up using a reflection class but your answer had enough information regarding classes to get me on the right track. My steps were this. I searched the plugin directory's php files for lines containing the property I wanted to use in my template. grep --include=\*.php -rnw '/path/to/plugin' -e "_some_property" I searched ...


1

The foolproof method here to grab a dynamic member variable is to use reflection! Lets say we have this class: class MyClass { private $myProperty = true; } We can use reflection to acquire the class, and the property: $class = new ReflectionClass("MyClass"); $property = $class->getProperty("myProperty"); We can then set that property to ...


0

I think you need do it like: wp_pagenavi( array( 'query' => $wp_query ) ); Alose, I wrote a plugin here: https://wordpress.org/plugins/easy-wp-page-navigation/installation/ It's easy to add page navigation in your blog :)


0

This works better for me overriding both blog posts and static page in Settings > Reading > Front page displays: <?php /** * Set custom post type archive as front page. * * @since 1.0.0 */ function ql_set_as_front_page( $query ) { if ( is_admin() || ! $query->is_main_query() ) { return; } if ( ql_is_front_page( $query ) ) { ...


0

You could try this in your functions.php <?php add_filter('rewrite_slugs', function($translated_slugs) { // the possible translations for your slug 'product' $translated_slugs = array( 'product' => array( 'pt' => array( 'has_archive' => true,'rewrite' => array('slug' => 'produto'), ), ...


0

My best solution! (works for any taxonomies,including "category") $your_taxonomy='category'; function my_Categ_tree($TermName='', $termID, $separator='', $parent_shown=true ){ $args = 'hierarchical=1&taxonomy='.$TermName.'&hide_empty=0&orderby=id&parent='; if ($parent_shown) {$term=get_term($termID , $TermName); ...


3

Here's a straight up simple solution. Requires you to have the most recent version of WordPress though. (or at least 4.1) Using nested taxonomy query. Taking what you have, and just adding to it a bit. $args = array( 'post-type' => 'episode', 'post-status' => 'publish', 'posts_per_page' => 4, 'tax_query' => array( ...


0

Thank you your filter worked a treat. FYI I added a check to see if in Admin to prevent changing the entry-title to my custom "longtitle" (default = menu-item-title) whilst editing a page. function pcdg_filter_title( $title, $post_id ) { if(!is_admin()) { if( $new_title = get_post_meta( $post_id, 'longtitle', true ) ) { ...


1

Is there a reason to execute the query in each individual div instead of looping the div within the query? <?php $my_query = new WP_Query( 'post_type=portfolio&showposts=13' ); while ( $my_query->have_posts() ) : $my_query->the_post(); ?> <div class="port1"> <?php the_title(); ?> </div> <?php endwhile; ?> ...


0

The problem lies in your soto_user_meta_box_save function. This function is tied to the save_post action, which means it will fire whenever any post of any post type is saved, not just your custom post type. You need to add a check inside this function so it aborts when testing the wrong post type: function soto_user_meta_box_save( $post_id ) { // ...


0

Did you try adding a count callback? // Register Custom Taxonomy function custom_taxonomy() { $labels = array( 'name' => _x( 'Taxonomies', 'Taxonomy General Name', 'text_domain' ), 'singular_name' => _x( 'Taxonomy', 'Taxonomy Singular Name', 'text_domain' ), 'menu_name' ...


0

Try Pippin's https://github.com/pippinsplugins/Restrict-Content-Pro/. You can create subscription levels and based on those you will be able to set up content using shortcodes such as: [restrict subscription="5"]service 1 -> 50 instances[/restrict] [restrict subscription="8"]service 2 -> 20 instances[/restrict] This is just the membership part. ...


2

I made a few adjustments. Once I created my two arrays, I combined them this way $merged_queries->posts = array_merge( $women->posts, $men->posts ); shuffle($merged_queries->posts); $merged_queries->post_count = $women->post_count + $men->post_count; while ( $merged_queries->have_posts() ) { $merged_queries->the_post(); // do ...


1

Found it! I was missing one custom capability. To the code above, I added this line: $rol->add_cap( 'edit_' . $cap[0] ); It gives the capability edit_ctpsinglename. (edit_pb_publicacion). And now it works just fine. Hope someone find's this useful.


0

I think what is missing in your code is the "add_action" call for your plugin init function, so all gets instantiated correctly within wp_json_server_before_serve hook. Should be something like this (note the last line): function quizno_api_init($server) { global $quizno_api_quiz; $quizno_api_quiz = new QN_API_Quiz($server); ...


1

I went through the two urls I added as comments, WordPress Codex documentation such as on register_taxonomy here some more and came up with this code that does seem to do the trick. Main addition is the added filter post_type_link to filter the cpt slug and load the term needed. // Register Custom Taxonomy function portfolio_taxonomy() { ...


1

This might solve your issue, and frankly, rewrites are still a little mistery to me, so I would not be able to help you out there, but there are two major issues in your code which you should first sort out before you try to sort out your rewrites Custom post type names (and for that matter, function names and custom taxonomy names) should be all small ...


0

Is your problem occurring in a multisite setup? If so, here is a solution: http://thereforei.am/2011/03/15/how-to-allow-administrators-to-edit-users-in-a-wordpress-network/ By default in a multisite setup, only Super Administrators can edit users.


2

I think the best way here would be to run three separate loops here (you can also do two loops, but then you need to get full posts in the men and women queries, combine them and shuffle them), the first two will be used to get 5 men and the second loop will get 2 women. You can adjust this as necessary. The third loop will use the info from the first two ...


0

To show a page at the custom post type 'home' you need to create a regular page with that slug. You can then add the page to the menu. I think I saw this in a different answer somewhere, but can't find it right now.


0

If you use those custom fields only for the company tagged posts, then it's sufficient to retrieve the custom fields without worrying about posts and tags: $tags = array('Professional Rating', 'Efficiency Rating', 'Referral Rating'); foreach ($tags as $tag) { $result = $wpdb->get_col( "SELECT meta_value FROM wp_postmeta WHERE meta_key = '$tag'" ); ...


0

You have two options. Either use get_field or the_field. get_field just reads out the field from the db without and screenoutput. like you did in your first line: $fields = get_field('testimonial'); the_field instead is get_field with an implied echo. <?php the_field('testimonial'); ?> so basically the_field would be enough. Aside you have to ...


0

I just should make Method 1 $object->set('meta_key', 'post_views_count'); Method 2 $query->set( 'meta_key', 'post_views_count' ); Method 3 $vars['meta_key'] = 'post_views_count';


0

You can run the same loop multiple times by using rewind_posts() to output each type separately. if( have_posts() ){ $types = array('post', 'lesson', 'series'); foreach( $types as $type ){ echo 'your container opens here for ' . $type; while( have_posts() ){ the_post(); if( $type == get_post_type() ){ ...


0

Here is the code I have gotten to work. It's not as elegant as Milo's answer, but it does work in my testing: EDIT: cleaned up and commented the code //----------------------------------------------------- // CONVERT TAXONOMY REQUEST TO POST REQUEST // This function looks at the request and determines // if a taxonomy request should be a post request // ...


0

$request['post_type'] should contain the requested post type for any custom type. The default post type will have a name, but no post_type. Pages will have pagename and no post_type. EDIT- determining custom post type based on taxonomy set in request: function cpt_request_filters( $request ){ if( ! is_admin() ){ global $wp_taxonomies; ...


0

Code Tricks have an article on this. The article is so short that quoting it will essentially copy it: //URL to fetch RSS feeds for custom post type feeds. www.your-website.com/feed/?post_type=custom_post_type_name //URL to fetch RSS feed for custom post type feeds including the custom taxonomy. ...


0

The old permalinks still work because the rewrite rules that support those permalinks still exist. When you register a post type, setting the rewrite argument generates the rules to resolve incoming requests. Rather than adding new rules in addition to the originals, just alter the original post type registration.


1

Don't create a new query and loop just to alter posts per page. Add a function hooked to pre_get_posts and alter whatever parameters you want in there before the query is run. This would go in your theme's functions.php file, or a plugin. function wpd_testimonials_query( $query ){ if( ! is_admin() && $query->is_post_type_archive( ...


2

Is the cooking blog under a CPT? In your CPT definition there is an argument to enable archives. See http://codex.wordpress.org/Function_Reference/register_post_type under "has_archive" That value will need to be set to true. After that, the CPT will be available at example.com/cpt-slug-here If you want to change that, you can set the value by overriding ...


0

after alot of try and error i find my solution: add_filter('post_type_link', 'events_permalink_structure', 10, 4); function events_permalink_structure($post_link, $post, $leavename, $sample){ $types=wp_get_object_terms( $post->ID, 'post_types' ); if (( 'animation' == $types[0]->slug )or ( 'comic' == $types[0]->slug )) { $post_link = ...


0

Your categories are, shopping , concerts and sports. So in order to create a category archive, you should follow category-{category-slug}.php Hence your file name should be : category-shopping.php category-sports.php category-concerts.php. And after this try with /event/category/concerts/ - this will solve your problem.



Top 50 recent answers are included