kirasiris
Forum Replies Created
-
That’s exactly what I needed, thanks dude!!. I’m not used to add supports to CPTs in that way so I was unaware of that!.
I will mark the question as solved.
I’m so so sorry for the late answer, I;ve not checked this website in 5 days!. Yes, that’s exactly what I mean!.
I’m so sorry for the late answer. I’m trying to create a link to showcase the demos of the themes being offered to sell.
For example,
https://bootstrapwp.com/themes/strappress/ …. not my websiteif you hover over the image, you can see a button re-directing to a different page. I’m trying to create that and since I’m not using the Advanced Custom Fields plugin, the code I posted in my original post is how you add it manually but for some reason it does not show any meta box for custom fields in the EDD cpt.
Forum: Developing with WordPress
In reply to: Terms wont show up in custom page template.Look here the whole html file but I already solved it, I forgot to put the reset_query :v . Thanks for helping suggesting tho.
<?php /* Template Name: Listado de Episodios Template Post Type: anime */ ?> <?php get_header(); ?> <div class="container"> <?php echo get_breadcrumb(); ?> <div class="row"> <!-- Sidebar --> <div class="col-md-3"> <div class="list-group"> <div class="list-group-item" style="padding:0;"> <?php if(has_post_thumbnail()) : ?> <img class="img-responsive" style="width:100%;" src="<?php the_post_thumbnail_url(); ?>"> <?php else : ?> <?php no_image(); ?> <?php endif; ?> </div> <?php if (!$post->post_parent ) : ?> <span class="list-group-item"><b>Estado:</b> <?php echo estado($post->ID); ?></span> <?php endif; ?> </div> </div> <!-- Main Content --> <div class="col-md-9"> <?php if(have_posts()) : the_post() ?> <!-- Titulo --> <div class="panel panel-default"> <div class="panel-heading" id="video_titulo"> <h1 class="panel-title"><i class="fa fa-header" aria-hidden="true"></i> <?php the_title(); ?> </h1> </div> </div> <!-- Sinopsis --> <div class="panel panel-default"> <div class="panel-heading"> <h1 class="panel-title"><i class="fa fa-book" aria-hidden="true"></i> Resumen</h1> </div> <div class="panel-body"> <?php the_content(); ?> </div> </div> <!-- Listado de Episodios --> <div class="panel panel-default"> <div class="panel-heading"> <h1 class="panel-title"><i class="fa fa-list" aria-hidden="true"></i> Lista de Episodios</h1> </div> <div class="panel-body" id="video_player"> <?php $listados = new WP_Query(array( 'post_type' => 'anime', 'order' => 'DESC', 'post_parent' => $post->ID, 'post_parent__not_in' => array(0), 'posts_per_page' => -1, )); ?> <table class="table table-hover" id="listado"> <?php if($listados->have_posts()) : ?> <tbody> <?php while($listados->have_posts()) : $listados->the_post(); ?> <tr> <td> <i class="fa fa-youtube-play text-success"></i> <a href="<?php the_permalink() ?>"><?php the_title(); ?></a> </td> </tr> <?php endwhile; ?> <?php else : ?> <div class="alert alert-danger" id="alerta_error">No existe ningun episodio.</div> </tbody> <?php endif; ?> /////// HERE <?php wp_reset_query(); ?> </table> </div> </div> <!-- Autores --> <div class="panel panel-default"> <div class="panel-heading"> <h1 class="panel-title"><i class="fa fa-users" aria-hidden="true"></i> Autores</h1> </div> <div class="panel-body"> </div> </div> <!-- Categorias --> <div class="panel panel-default"> <div class="panel-heading"> <h1 class="panel-title"><i class="fa fa-tag" aria-hidden="true"></i> Categorias</h1> </div> <div class="panel-body"> <?php global $post; $terms = wp_get_post_terms( get_the_ID(),'categorias_anime'); if ($terms) { $output = array(); foreach ($terms as $term) { $output[] = '<a href="' .get_term_link( $term->slug, 'categorias_anime') .'"><span class="label label-success">' .$term->name .'</span></a>'; } echo join( ' ', $output ); } else { echo '<a><span class="label label-success">Sin categoria</span></a>'; } ?> </div> </div> <!-- Tags --> <div class="panel panel-default"> <div class="panel-heading"> <h1 class="panel-title"><i class="fa fa-tags" aria-hidden="true"></i> Tags</h1> </div> <div class="panel-body"> <?php global $post; $terms = wp_get_post_terms( get_the_ID(), 'tags_anime' ); if ($terms) { $output = array(); foreach ($terms as $term) { $output[] = '<a href="' .get_term_link( $term->slug, 'tags_anime') .'"><span class="label label-success">' .$term->name .'</span></a>'; } echo join( ' ', $output ); } else { echo '<a><span class="label label-success">Sin tags</span></a>'; } ?> </div> </div> <!-- Comentarios --> <div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title"><i class="fa fa-comments"></i> Comentarios <span class="pull-right"> <div class="fb-like" data-href="<?php the_permalink(); ?>" data-layout="button" data-action="like" data-size="small" data-show-faces="true" data-share="true"></div> </span> </h3> </div> <?php comments_template(); ?> </div> <?php endif; ?> </div> </div> </div> <?php get_footer(); ?>
Forum: Developing with WordPress
In reply to: How to get metadata in select?Nothing yet man. It just keeps retrieving the “Ningun resultado”. I actually posted the same question in Stackoverflow as well. If you want to keep yourself up to date in case you might need it later on or if you want to keep helping, here is the link: QUESTION.
You can see there what other “extra” stuff I have tried.
Forum: Developing with WordPress
In reply to: How to get metadata in select?Well I just found out I can not edit the question(they should have implemented it long ago..) so I will just paste them(html file and function) here:
HTML file(custom page):
<?php /* Template Name: Direcotorio Template Post Type: page */ ?> <?php get_header(); ?> <div class="container"> <div class="row"> <div id="my-adv-search"> <!-- Post Type --> <div class="col-md-3"> <div class="form-group"> <label for="q_post_type">Tipo</label> <select class="form-control" id="q_post_type"> <option selected>Selecciona una opcion</option> <?php $args = array( 'public' => true, '_builtin' => false, ); $post_types = get_post_types($args); foreach( $post_types as $post_type ) { echo '<option>' . $post_type . '</option>' ; } ?> </select> </div> </div> <!-- Genero --> <div class="col-md-3"> <div class="form-group"> <label for="q_taxonomy">Genero</label> <select class="form-control" multiple id="q_taxonomy"> <option value="any" selected>Selecciona una opcion</option> <?php $args = array( 'public' => true, '_builtin' => false ); $output = 'names'; // or objects $operator = 'and'; // 'and' or 'or' $taxonomies = get_taxonomies( $args, $output, $operator ); if ( $taxonomies ) { foreach ( $taxonomies as $taxonomy ) { echo '<option>' . $taxonomy . '</option>'; } } ?> </select> </div> </div> <!-- Estado --> <div class="col-md-3"> <div class="form-group"> <label for="q_orderby">Estado</label> <select class="form-control" id="q_orderby"> <option value="any" selected>Selecciona una opcion</option> <?php foreach ( [ 'author' => 'Author', 'comment_count' => 'Popularity (# of Comments)', 'year' => 'Year', 'en_emision' => 'Emision', 'en_final' => 'Finalizado', //'order' => 'ASC ? DESC', ] as $value => $label ) { printf( '<option value="%s">%s</option>', esc_attr( $value ), esc_html( $label ) ); } ?> </select> </div> </div> <!-- Year --> <div class="col-md-3"> <div class="form-group"> <label for="q_year">A?o</label> <select class="form-control" id="q_year"> <option value="any" selected>Selecciona una opcion</option> <?php $args = array( 'public' => true, '_builtin' => false, 'type' => 'yearly', 'format' => 'option', ); wp_get_archives($args); ?> </select> </div> </div> <!-- Nonce field. --> <?php wp_nonce_field( 'my-adv-search', 'q_nonce' ); ?> <!-- Search Button --> <div class="col-md-12"> <input type="submit" class="btn btn-success" id="buscar_btn" value="Search"> <br><br> <noscript><b>Tu buscador no soporta Javascript, haciendo imposible mostrar los posts.</b></noscript> <div id="resultados"><div class="cargando_medio"></div></div> </div> </div><!-- End #my-adv-search --> </div> </div> <?php get_footer(); ?> <script type="text/javascript"> jQuery( function( $ ){ var ajaxurl = '/wptests/wp-admin/admin-ajax.php'; function searchPosts( btn ) { var _btn_text = btn.value;//, q_order; btn.disabled = true; btn.value = 'Searching..'; // q_order = $( '#q_order-asc' ).is( ':checked' ) ? // 'ASC' : 'DESC'; return $.post( ajaxurl, { action: 'my_adv_search', q_nonce: $( '#q_nonce' ).val(), q_post_type: $( '#q_post_type' ).val(), q_taxonomy: $( '#q_taxonomy' ).val(), q_year: $( '#q_year' ).val(), q_orderby: $( '#q_orderby' ).val(), // q_order: q_order, } ).done( function( s ){ if ( 'session_expired' === s ) { location.reload(); return; } $( '#resultados' ).html( s ); } ).always( function(){ btn.value = _btn_text; btn.disabled = false; } ); } $( '#buscar_btn', '#my-adv-search' ).on( 'click', function( e ){ e.preventDefault(); // Run AJAX search. searchPosts( this ); // Remove button focus. this.blur(); } ); } ); </script>
and the function file: which is almost done, you will see where I’m having troubles at:
// Buscador Avanzado add_action( 'wp_ajax_my_adv_search', 'ajax_my_adv_search' ); add_action( 'wp_ajax_nopriv_my_adv_search', 'ajax_my_adv_search' ); function ajax_my_adv_search() { if ( ! check_ajax_referer( 'my-adv-search', 'q_nonce', false ) ) { echo 'session_expired'; wp_die(); } $post_type = isset( $_POST['q_post_type'] ) ? $_POST['q_post_type'] : ''; $taxonomy = isset( $_POST['q_taxonomy'] ) ? $_POST['q_taxonomy'] : []; $year = isset( $_POST['q_year'] ) ? $_POST['q_year'] : ''; $orderby = isset( $_POST['q_orderby'] ) ? $_POST['q_orderby'] : []; $order = isset( $_POST['q_order'] ) ? $_POST['q_order'] : ''; // Note that if $post_type is 'any', all post statuses will be included. In // that case, you may want to set specific post statuses below. $post_status = 'publish'; // by Taxonomy $taxonomy = array_filter( (array) $taxonomy ); if ( ! in_array( 'any', $taxonomy ) ) { $taxonomy = array_unique( array_map( 'trim', $taxonomy ) ); add_filter( 'posts_join', function( $c ) use ( $taxonomy ) { if ( ! empty( $taxonomy ) ) { global $wpdb; // 1 below is one/number and not the lowercase of L $c .= " INNER JOIN {$wpdb->term_relationships} AS ctr1 ON ctr1.object_id = {$wpdb->posts}.ID" . " INNER JOIN {$wpdb->term_taxonomy} AS ctt1 ON ctt1.term_taxonomy_id = ctr1.term_taxonomy_id"; } return $c; } ); add_filter( 'posts_where', function( $c ) use ( $taxonomy ) { if ( ! empty( $taxonomy ) ) { $tax_list = array_map( 'esc_sql', $taxonomy ); $tax_list = "'" . implode( "', '", $tax_list ) . "'"; // 1 below is one/number and not the lowercase of L $c .= " AND ( ctt1.taxonomy IN ($tax_list) )"; } return $c; } ); } // by Custom Field Value - Metadata $orderby = array_filter( (array) $orderby ); if ( in_array( 'any', $orderby ) ) { // Don't sort by post date. $orderby2 = false; } else { $orderby = array_unique( array_map( 'trim', $orderby ) ); // TRUE if we're sorting by year. $ob_year = false; foreach ( $orderby as $i => $s ) { // Sort posts by year. if ( 'year' === $s ) { $ob_year = true; unset( $orderby[ $i ] ); } //// PROBLEM BEGINS HERE // Sort posts by meta value en_emision from meta key estado_de_video. Note that this would only return // posts that have the custom field 'en_emision'. if ( 'en_emision' === $s ) { $meta_key = 'en_emision'; $orderby2 = 'meta_value'; unset( $orderby[ $i ] ); } // Sort posts by meta value en_final from meta key estado_de_video. Note that this would only return // posts that have the custom field 'en_final'. if ( 'en_final' === $s ) { $meta_key = 'en_final'; $orderby2 = 'meta_value'; unset( $orderby[ $i ] ); } } //// PROBLEM ENDS HERE add_filter( 'posts_orderby', function( $c, $q ) use ( $ob_year ) { if ( $ob_year ) { global $wpdb; // Use the value parsed by WP_Query. $order = $q->get( 'order' ); $c .= $c ? ', ' : ''; $c .= "YEAR({$wpdb->posts}.post_date) $order"; } return $c; }, 10, 2 ); $ok = isset( $orderby2 ); if ( ! $ok && empty( $orderby ) ) { // Don't sort by post date. $orderby2 = false; } elseif ( ! $ok ) { // Pass to WP_Query as a string. $orderby2 = implode( ' ', $orderby ); } } // by Year if ( ! is_numeric( $year ) ) { $year = ''; } $q = new WP_Query( [ 'post_status' => $post_status, 'post_type' => array($post_type), 'posts_per_page' => -1, 'post_parent' => 0, 'year' => $year, 'meta_key' => isset( $meta_key ) ? $meta_key : '', 'orderby' => $orderby2, 'order' => $order, ] ); if ( $q->have_posts() ) { echo '<ul>'; while ( $q->have_posts() ) { $q->the_post(); ?> <li><a href="<?php the_permalink(); ?>"><?php the_title() ?></a></li> <?php } echo '</ul>'; } else { echo '<div class="alert alert-danger">Ningun Resultado</div>'; } wp_die(); }
If you guys want to implement them in your theme just to test it out or to do something similar exactly, feel free to do so(should be easy to implement); I don’t mind but yeah, that’s it. I will probably edit the taxonomy one later on just to make the taxonomies(categories or tags; I have not decided yet) appear according to what post type has been selected(but that’s not necessary right now; probably another question if I dont figure it out.).
Bare with me!!.
Thanks again.
Forum: Developing with WordPress
In reply to: How to get metadata in select?Well I’m building an advanced search page for my post types. This page will sort post by looking into these “post_type, taxonomy, meta_value(en_emision or en_final) and year”.
Depending on what option is selected the posts should appear
I already have function which is actually the one that I’m trying to use with this page but the problem is that I just cannot make it work(with the meta values), I mean if I select a cpt it shows the posts, if I select a taxonomy it shows me the posts related to that taxonomy and the year works fine as well.
I already said that I have function which is pretty much done I just need to edit a bit more and a bit of help.
If you guys want me to post another question and put both the html file and the function(which is very large) I will be more than please and grateful for the help.
- This reply was modified 6 years, 5 months ago by kirasiris.
Forum: Developing with WordPress
In reply to: How to display custom taxonomy for CPTI solved it.
<?php global $post; $terms = wp_get_post_terms($post->ID, 'tags_movie'); if ($terms) { $output = array(); foreach ($terms as $term) { $output[] = '<a href="' .get_term_link( $term->slug, 'tags_movie') .'">' .$term->name .'</a>'; } echo join( ', ', $output ); }; ?>
Forum: Developing with WordPress
In reply to: Why is there an infinite loop in my CPT?I already fixed it. The I checked everything you guys said but it did not fix it so I tried by changing the name to the spanish version “peliculas” and it finally worked. I really have not idea what caused it(the error) or why did it happen since it was not the first time in which I create a “movies” cpt but oh well, is fixed now.
NOTE: The infinite loop was not showing me nothing, the only thing it did was making the windows(from the browser) bigger…. as if it was a infinite loop, without showing nothing.
Thanks, I will mark the question as solved.
Forum: Developing with WordPress
In reply to: Adding Numeric Pagination for Archive, Search and IndexYes, thank you I did not realize I was returning nothing in the function but thank you for helping. Yes, you were right about not wanting to use is_singular() but somehow it did not work before, now it does.
Forum: Developing with WordPress
In reply to: Adding Numeric Pagination for Archive, Search and IndexI’m sorry I did not explain myself very clear. I’m not trying to avoid pagination,
in fact I want to display it in index, archive and searchForum: Developing with WordPress
In reply to: How to create custom settings in CustomizerDon’t you think is better to create a CPT(Custom Post Type)? in that way you can add more “team members” from the post editor without having to depend in the customizer which it only works in the front-page (for what I know and for what I have tried before xD)
Forum: Developing with WordPress
In reply to: Multiple Blog CategoriesNo offenses dude but we are not a free code service; when asking a question try to at least shows us your code to see how much effort you have put into it and then all the others developers will be able to tell you where’s the syntax error or even better, we can give you your block of code completely fixed…. I highly recommend you to watch some YouTube tutorials first.
I know you already solved your problem by yourself but still “do your homework before coming to class”… look for Traversy Media on Youtube I believe he has a WordPress tutorials playlist.
Hey, I solved it. Silly me… I did not realize that I had setup 5 post per page in the settings>reading>Blog pages show at most.
After I realize that, I still wanted to show all the CPT posts without limits, so in my custom page I had to edit the query which displays the CPTS by adding this:
$snippets_query = new WP_Query(array( 'post_type' => 'snippets', 'order' => 'DESC', 'posts_per_page' => -1, ));
and that fixed it. Thanks for helping. I’m now closing this question as solved.
Forum: Developing with WordPress
In reply to: Custom Post type with Buildin WordPress CategoriesYou will first need to build your own CPT and link it with a Custom Taxonomy:
This is a CPT(I use it in my very own personal website.) for Portfolios. You will need to change kevinurielfonseca for yours theme name.
<?php function custom_portfolio_type() { // Set UI labels for Custom Post Type $portfolio_labels = array( 'name' => _x( 'Portfolios', 'Post Type General Name', 'kevinurielfonseca' ), 'singular_name' => _x( 'Portfolio', 'Post Type Singular Name', 'kevinurielfonseca' ), 'menu_name' => __( 'Portfolios', 'kevinurielfonseca' ), 'name_admin_bar' => __( 'Portfolio', 'kevinurielfonseca' ), 'archives' => __( 'Portfolio Archives', 'kevinurielfonseca' ), 'attributes' => __( 'Portfolio Attributes', 'kevinurielfonseca' ), 'parent_item_colon' => __( 'Parent Portfolio', 'kevinurielfonseca' ), 'all_items' => __( 'All Portfolios', 'kevinurielfonseca' ), 'add_new_item' => __( 'Add New Portfolio', 'kevinurielfonseca' ), 'add_new' => __( 'Add Portfolio', 'kevinurielfonseca' ), 'new_item' => __( 'New Item', 'kevinurielfonseca' ), 'edit_item' => __( 'Edit Portfolio', 'kevinurielfonseca' ), 'update_item' => __( 'Update Portfolio', 'kevinurielfonseca' ), 'view_item' => __( 'View Portfolio', 'kevinurielfonseca' ), 'view_items' => __( 'View Portfolios', 'kevinurielfonseca' ), 'search_items' => __( 'Search Portfolio', 'kevinurielfonseca' ), 'not_found' => __( 'Not Found', 'kevinurielfonseca' ), 'not_found_in_trash' => __( 'Not found in Trash', 'kevinurielfonseca' ), 'featured_image' => __( 'Featured Image', 'kevinurielfonseca' ), 'set_featured_image' => __( 'Set featured image', 'kevinurielfonseca' ), 'remove_featured_image' => __( 'Remove featured image', 'kevinurielfonseca' ), 'use_featured_image' => __( 'Use as featured image', 'kevinurielfonseca' ), 'insert_into_item' => __( 'Insert into item', 'kevinurielfonseca' ), 'uploaded_to_this_item' => __( 'Uploaded to this item', 'kevinurielfonseca' ), 'items_list' => __( 'Items list', 'kevinurielfonseca' ), 'items_list_navigation' => __( 'Items list navigation', 'kevinurielfonseca' ), 'filter_items_list' => __( 'Filter items list', 'kevinurielfonseca' ), ); // Set other options for Custom Post Type $portfolio_args = array( 'label' => __( 'portfolios', 'kevinurielfonseca' ), 'description' => __( 'Portfolio Templates and Snippets', 'kevinurielfonseca' ), 'labels' => $portfolio_labels, // Features this CPT supports in Post Editor 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions','post-formats'), // You can associate this CPT with a taxonomy or custom taxonomy. 'taxonomies' => array( 'portfolio_categories'), /* A hierarchical CPT is like Pages and can have * Parent and child items. A non-hierarchical CPT * is like Posts. */ 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'show_in_admin_bar' => true, 'menu_position' => 5, 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => 'post', 'menu_icon' => 'dashicons-format-gallery', ); // Registering your Custom Post Type register_post_type( 'portfolios', $portfolio_args ); } /* Hook into the 'init' action so that the function * Containing our post type registration is not * unnecessarily executed. */ add_action( 'init', 'custom_portfolio_type', 0 ); ?>
and here is the Custom Taxonomy for the CPT that I pasted above:
<?php //========================= Taxonomy for Portfolio Custom Post Type ===========================// //create a custom taxonomy name it topics for your posts function portfolio_categories_taxonomy() { // Add new taxonomy, make it hierarchical like categories //first do the translations part for GUI $portfolio_cats = array( 'name' => _x( 'Portfolio Categories', 'taxonomy general name' ), 'singular_name' => _x( 'Portfolio Category', 'taxonomy singular name' ), 'search_items' => __( 'Search Portfolio Categories' ), 'all_items' => __( 'All Portfolio Categories' ), 'parent_item' => __( 'Parent Portfolio Category' ), 'parent_item_colon' => __( 'Parent Portfolio Category:' ), 'edit_item' => __( 'Edit Portfolio Category' ), 'update_item' => __( 'Update Portfolio Category' ), 'add_new_item' => __( 'Add New Portfolio Category' ), 'new_item_name' => __( 'New Portfolio Category' ), 'menu_name' => __( 'Portfolio Categories' ), ); // Now register the taxonomy register_taxonomy('portfolio_categories',array('portfolios'), array( 'hierarchical' => true, 'labels' => $portfolio_cats, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'portfolio_categories' ), )); } add_action( 'init', 'portfolio_categories_taxonomy', 0 ); //========================= Tags for Portfolio Custom Type ===========================// //hook into the init action and call create_topics_nonhierarchical_taxonomy when it fires function portfolio_tags_taxonomy() { // Labels part for the GUI $portfolio_tags = array( 'name' => _x( 'Portfolio Tags', 'taxonomy general name' ), 'singular_name' => _x( 'Portfolio Tag', 'taxonomy singular name' ), 'search_items' => __( 'Search Portfolio Tags' ), 'popular_items' => __( 'Popular Portfolio Tags' ), 'all_items' => __( 'All Portfolio Tags' ), 'parent_item' => null, 'parent_item_colon' => null, 'edit_item' => __( 'Edit Portfolio Tag' ), 'update_item' => __( 'Update Portfolio Tag' ), 'add_new_item' => __( 'Add New Portfolio Tag' ), 'new_item_name' => __( 'New Portfolio Tag Name' ), 'separate_items_with_commas' => __( 'Separate portfolio tags with commas' ), 'add_or_remove_items' => __( 'Add or remove portfolio tags' ), 'choose_from_most_used' => __( 'Choose from the most used portfolio tags' ), 'menu_name' => __( 'Portfolio Tags' ), ); // Now register the non-hierarchical taxonomy like tag register_taxonomy('portfolio_tags',array('portfolios'),array( 'hierarchical' => false, 'labels' => $portfolio_tags, 'show_ui' => true, 'show_admin_column' => true, 'update_count_callback' => '_update_post_term_count', 'query_var' => true, 'rewrite' => array( 'slug' => 'portfolio_tags' ), )); } add_action( 'init', 'portfolio_tags_taxonomy', 0 ); ?>
I pretty much give you everything you need. Now the only thing you have left to by your own is the custom page template in order to display the posts under the CPT(Portfolio). I can actually give you a link to my website in which I explain how to do it (detail by detail) but its now allowed to advertise URL’s